Created
February 18, 2018 11:24
-
-
Save YuheiNakasaka/d9b068b68a199b47607688b47b063598 to your computer and use it in GitHub Desktop.
適当にflowの練習
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @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