Skip to content

Instantly share code, notes, and snippets.

@robinpokorny
Created January 2, 2017 13:47
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 robinpokorny/b18ecd4565104831a78b02a43d62c1af to your computer and use it in GitHub Desktop.
Save robinpokorny/b18ecd4565104831a78b02a43d62c1af to your computer and use it in GitHub Desktop.
Flowtype and Promise.resolve
// @flow
// BAD
// Will throw this type error:
// ‘undefined This type is incompatible with some incompatible instantiation of `T`’
const resolve = <T> (init?: T): Promise<T> => Promise.resolve(init)
// GOOD
// The return promise type is `?T`, i.e. nullable T
const resolve = <T> (init?: T): Promise<?T> => Promise.resolve(init)
@stryju
Copy link

stryju commented Jan 4, 2017

flow shouldn't throw anything if you make init required :)

@robinpokorny
Copy link
Author

robinpokorny commented Jan 6, 2017

@stryju, Yeah, but then it would be kind of simple, right? 😄

I mean, I want init optional. (BTW, as it is for Promise.resolve.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment