Skip to content

Instantly share code, notes, and snippets.

@YuheiNakasaka
Created February 18, 2018 11:24
Show Gist options
  • Save YuheiNakasaka/d9b068b68a199b47607688b47b063598 to your computer and use it in GitHub Desktop.
Save YuheiNakasaka/d9b068b68a199b47607688b47b063598 to your computer and use it in GitHub Desktop.
適当にflowの練習
/* @flow */
function p(w: string) {
return new Promise(resolve => {
setTimeout(() => {
resolve(w);
}, 100);
});
}
p.then((resp: string) => {
console.log(`${resp} is returned!`);
})
type Obj = {
a: string,
b: number,
c?: boolean
}
const myObj: Obj = {
a: "hoge",
b: 1,
c: true
}
const arr: Array<string> = ["a"];
interface Callable {
say(string): string;
}
class Hoge implements Callable {
say(w: string): string {
return `${w} retured!`;
}
}
const hoge : Hoge = new Hoge;
hoge.say("test");
interface CallableGenerics<T> {
say(T):T;
}
class Foo implements CallableGenerics<string> {
say(w: string): string {
return w;
}
}
const foo: Foo = new Foo;
foo.say("test generics");
function unionFunc(v: number | string | boolean): string {
return String(v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment