Generic parameter inference for Promise.then oddity #11022
Labels
Breaking Change
Would introduce errors in existing code
Bug
A bug in TypeScript
Fixed
A PR has been merged for this issue
Milestone
TypeScript Version: 1.8.0 / nightly (2.0.5-dev.20160919)
Code
Expected behavior:
U
should be inferred to bestring | null
as that solves the type constraints. It can be verified by explicitly addingthen<string | null>.(...)
which type checks.Actual behavior:
TS errors with
Argument of type '(_: string) => Thenable<string> | null' is not assignable to parameter of type '(value: string) => string | Thenable<string>'.
Oddities:
The following changes make the error disappear, while I expect them to have no relevance to the type of the closure:
declare let x
belowdeclare function f
andg
.Thenable<number>
.a: T
, that would makeThenable
strictly covariant.(_) => (Math.random() < 0.5) ? f() : g()
The text was updated successfully, but these errors were encountered: