-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
.call
on an union with different arguments counts fails when passing any
#58468
Comments
So in this case we end up with multiple inference candidates. We have:
When multiple inference candidates are present, TS tries to select the best match based on different criteria. Since contravariant candidates don't overlap sufficiently enough the first one gets picked as overall Since we have both some(inference.contraCandidates, t => isTypeSubtypeOf(inferredCovariantType, t))
So it turns out one of my PR fixes this case alrady: #57909 But what happens in the implementation here got me thinking... why do we even have multiple contravariant candidates here? we do have that because the inference infer from each of your signatures separately here. This is kinda a single call though. TS is able to combine union (or intersection) signatures into one. Shouldn't we then infer from that combined signature here? So that led me to creating this experiment that also addresses this issue: #58482 |
🔎 Search Terms
call union expected arguments but got
🕗 Version & Regression Information
Before version 4.5 both the
.call
s in the example below failed. Since then,.call(null, something-not-any)
is accepted and.call(null, something-any)
failes.⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.5.0-beta#code/CYUwxgNghgTiAEYD2A7AzgF3gMxQLngApCBKeAXgD54A3JAS2DIB8jCoCUBXAWwCMQMMlVoMmAKHGhIsBMnRYAHp14CYAbinhocRKkzwAngSgpDm8bgB0YKBAiFu9gDTxFJTddv3HXF0Y9JXEJDQOD3CyA
💻 Code
🙁 Actual behavior
The line marked as
// error
gives the following error:🙂 Expected behavior
It should be accepted, the same as the other lines are accepted.
Additional information about the issue
No response
TODO for myself: Remove
@ts-ignore
in https://github.com/babel/babel/blob/main/packages/babel-generator/src/printer.ts#L717 once this is fixedThe text was updated successfully, but these errors were encountered: