-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Unexpected behavior in extends clause that has two inferred rest types with constraints #50993
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
Comments
The problem here is likely related to the logic in this branch. It never handled 2 variadic positions used like this - what you see in the result is not the inferred result but rather just constraints of those type params (coming from your One could argue that this is hard to infer because the lengths of those leading and trailing tuples are not known but OTOH inferring from strings using template literal types already comes with some greedy/non-greedy behaviors baked into the language and similar rules could be just used here. The "inferred" match is equivalent to But note that because of what I have described above... |
I don't know that we've ever supported inference to two rest elements of a tuple that has one or more fixed elements between them. What ends up happening is that the inferred extends type actually ends up as Since both |
This is unfortunately a design limitation as we have a very narrow heuristic that provides rudimentary support for inferring to multiple rest types in a tuple. It's not clear at this time whether this is something we want to extend. While a useful minimal repro, the example shown in the issue description doesn't illustrate a need that would be sufficient motivation to reevaluate this limitation. It would be helpful to understand the specific needs this issue is trying to address. |
Design limitation is fine by me. I ran into it while answering a StackOverflow question and thought it might be a bug, but I don't have an actual need for it to get addressed. |
I don't have any additional feedback, shall we close the issue as a design limitation? |
Bug Report
π Search Terms
π Version & Regression Information
Version 4.7 and higher (including nightly)
β― Playground Link
TypeScript playground
π» Code
π Actual behavior
Similar to
Prefix
, which extracts a tuple of leading zeroes and works as expected, I tried to constructPrefixSuffix
, to extract both the leading and trailing zeroes. When applied to an array with multiple ones,PrefixSuffix<[0,0,1,1,0,0]>
evaluates to{p: 0[], s: 0[]}
instead ofnever
.π Expected behavior
I would have expected
PrefixSuffix<[0,0,1,1,0,0]>
to evaluate tonever
, as[0,0,1,1,0,0]
cannot extend an array that contains only a single1
. I also would have expectedPrefixSuffix<[0,0,1,0,0]>
to infer tuple types{p: [0,0], s: [0,0]}
rather than{p: 0[], s: 0[]}
, but maybe that's just a design limitation.The text was updated successfully, but these errors were encountered: