Created
January 2, 2017 13:47
-
-
Save robinpokorny/b18ecd4565104831a78b02a43d62c1af to your computer and use it in GitHub Desktop.
Flowtype and Promise.resolve
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 | |
// 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@stryju, Yeah, but then it would be kind of simple, right? 😄
I mean, I want
init
optional. (BTW, as it is forPromise.resolve
.)