New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange behavior in type argument inference with Promises #248
Comments
Two proposals here:
|
Proposal: Now the new second and third sub-bullet in section 3.8.6 would look like this:
|
The reason we pick the last signature instead of the first one is methods like addEventListener, which have lots of string literal overloads, followed by a string overload. We want to pick the most general overload that fits, or at least one that is not more specific than another one. |
This bug is observable in the following type baselines:
|
This is a duplicate of #1729 |
In the old compiler, with either ordering of the overloads, newPromise had type
Promise<{}>
.In the new compiler, if the number signature comes first, we get an error. If the string signature comes first, newPromise is of type
Promise<number>
! This is very inconsistent.We have based this on the notion that the last overload will always be more general than the preceding overloads. However, with disjoint overloads, we are essentially giving the last one undue priority. The rule of thumb is that in a call, the first overload has priority, so giving the last one priority when passing a callback seems really unintuitive.
The text was updated successfully, but these errors were encountered: