Closed
Description
TypeScript Version: 2.1.4
Code
declare let p: Promise<number>;
declare let p2: Promise<number|string>;
// TS infers pfinal to be Promise<number> incorrectly.
// pfinal should be Promise<number|string>
let pfinal = p.then(_ => p2);
Expected behavior:
Pfinal should be Promise<number|string>
Actual behavior:
Pfinal is inferred to be Promise<number>
Note any choice of Promise<T>
and Promise<S>
where S is a supertype of T will trigger this error.
This happens because then function overload then(onfulfilled?: ((value: T) => T | PromiseLike<T>) | undefined | null, ...): Promise<T>;
is matching before the one with the free type parameter TResult
.
As far I can tell it is a consequence of the fix in #10524 (comment) and not a desired change.
//cc @calebegg