Skip to content

Instantly share code, notes, and snippets.

@Olical
Last active April 25, 2016 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Olical/daa700207b581a1094c18762a5688842 to your computer and use it in GitHub Desktop.
Save Olical/daa700207b581a1094c18762a5688842 to your computer and use it in GitHub Desktop.
Flow + Babel = <3 or at least a slight improvement
// @flow
type Person = {
name: string,
age: number
}
function getPeople (): Promise<Array<Person>> {
const people: Array<Person> = [
{name: 'Foo', age: 21},
{name: 'Bar', age: 31},
{name: 'Baz', age: 41}
]
return new Promise((resolve) => {
setTimeout(resolve(people), 1000)
})
}
async function run () {
const people: Array<Person> = await getPeople()
const names: Array<string> = people.map((p: Person) => p.name)
}
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment