You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functiongetDate(): Promise<Date>{returnPromise.resolve(newDate());}functiongetFoo(): Promise<{}>{returnPromise.resolve({});}functiondoFoo() : Promise<number>{// Error: Type 'Promise<Date>' is not assignable to type 'Promise<number>'.return(getDate().then(()=>{return(getFoo().then(()=>{return10;}));}));}
Expected behavior:
No compilation error
Actual behavior:
Compiler error: Type 'Promise<Date>' is not assignable to type 'Promise<number>'.
Futher Notes
Changing getFoo to return any other value, e.g. function getFoo(): Promise<void> fixes the compilation error.
The text was updated successfully, but these errors were encountered:
It looks like the order of the overloads of .then in lib.es2015.promise.d.ts are wrong.
I could be wrong but my understanding is that they need to be declared in decreasing order of specificity. When I change this, it fixes the error.
Here is a more minimal repro (note that no error is reported but that the type of result is wrong).
functiongetFoo(): Promise<{}>{returnPromise.resolve({});}functiondoFoo(): Promise<number>{constresult=getFoo().then(()=>{return10;});returnresult;// Result has type Promise<{}> should be Promise<number>}
@NoelAbrahams
Yes I think you are right. Regardless the overload order should be fixed because it is always going to pick the wrong one for cases where T is assignable to TResult as is the case when TResult is {} for any T.
TypeScript Version: 2.1.4
Code
Expected behavior:
No compilation error
Actual behavior:
Compiler error:
Type 'Promise<Date>' is not assignable to type 'Promise<number>'
.Futher Notes
Changing
getFoo
to return any other value, e.g.function getFoo(): Promise<void>
fixes the compilation error.The text was updated successfully, but these errors were encountered: