-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
Description
While it is possible to create types like Promise<Promise<T>>, await and Promise#then do not unwrap to T correctly the same way they do in JavaScript implementations.
[try flow]
declare function wrap<T>(fn: T): Promise<T>;
async function main() {
let val: Promise<Promise<42>> = wrap(Promise.resolve(42));
let res: 42 = await val;
val.then((res: 42) => {
// ...
});
}Error one: await
7: let res: 42 = await val;
^ Promise. This type is incompatible with
7: let res: 42 = await val;
^ number literal `42`
Error two: .then
9: val.then((res: 42) => {
^ function. This type is incompatible with the expected param type of
[LIB] static/v0.62.0/flowlib/core.js:598: onFulfill?: (value: R) => Promise<U> | U,
^ function type
The first parameter is incompatible:
6: let val: Promise<Promise<42>> = wrap(Promise.resolve(42));
^ Promise. This type is incompatible with
9: val.then((res: 42) => {
^ number literal `42`
Reactions are currently unavailable