Shorter tuple inference gets picked over longer inference when both come from rests #57981
Labels
Help Wanted
You can do this
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
π Search Terms
inference contravariant covariance rest shorter longer tuples
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.5.0-dev.20240327#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVNQB4BBeEADwxFWAGd44pg8IBPeNAa1RwHdUA2gF0AfAAoAsACh48WAHMAXPDEA6dQtrLiASngBeEfABuOLMAA002etWbt0ndoDc0sHloZ4WVIhAw4YAMCMTEoZVRkAFsAI389Q3gAbwBfC3gARnSAJh1neAB6AvgAUXIAB3AqIOy5GHlo6gxadJjkL3kcLwBmVTFsgFYBgBYdaSLZWQA9AH54d1RPb19-QOUBcPhI2P8hNw8vHz8AkGBa-RCwiOi4mFaZ652YBKNU9Iy8wuKcTnHiydm8wOy2OgWy622tz2UgWSyOq1O3WCiFQoU2kP890etxeyTSmTk9FhGE+Ex+f0m8EBxJBCOA3XWGWhQA
π» Code
π Actual behavior
inferred
is[a: number]
and the function call failsπ Expected behavior
inferred
should be[number, number]
and the function call should succeed.Additional information about the issue
Based on
inferred2
andinferred3
we can see that the covariant inference is preferred in a situation like this. The problem is the.length
mismatch between those 2 candidates but since the contravariant candidate comes from a rest position it should be ignored when comparing those 2 candidates and the covariant inference should be preferredThe text was updated successfully, but these errors were encountered: