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.
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>}
Noel Abrahams (@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.
Activity
aluanhaddad commentedon Dec 18, 2016
It looks like the order of the overloads of
.theninlib.es2015.promise.d.tsare 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
resultis wrong).NoelAbrahams commentedon Dec 18, 2016
Aluan Haddad (@aluanhaddad), I might even suspect that the non-generic overload of
thenis redundant and should be removed.aluanhaddad commentedon Dec 18, 2016
Noel Abrahams (@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
Tis assignable toTResultas is the case whenTResultis{}for anyT.