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
Actual behavior:
function a doesn't compile. The return type of the return statement is inferred as Promise<void>, while it should be inferred as Promise<any>, which is compatible with the intended return type (Promise<number>) of the parent function (a), just like type is correctly inferred as Promise<number> in the function b.
TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)
Code
Expected behavior:
Should compile.
Actual behavior:
function
a
doesn't compile. The return type of the return statement is inferred asPromise<void>
, while it should be inferred asPromise<any>
, which is compatible with the intended return type (Promise<number>
) of the parent function (a
), just like type is correctly inferred asPromise<number>
in the functionb
.The offending part here is the library definitions for the
Promise
interface, at https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es2015.promise.d.ts#L31. The linked definition ofthen
is matched on the result ofPromise.resolve()
, which is aPromise<void>
, and the return type is inferred asPromise<void>
only. Apparently order matters, and the correct matching for that expression should be https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es2015.promise.d.ts#L47 instead, so the return type is inferred asPromise<any>
instead.Simply re-ordering those definitions of
.then
solves the issue. But I am not sure what the further implications are.The text was updated successfully, but these errors were encountered: