Re-add strict concat signature#9997
Merged
Merged
Conversation
Member
|
👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9901. Broken by #6629 after we missed the bug during the discussion in #6594.
#6629 introduces a new type for concat:
(...items: (T | T[])[]): T[]. This means thatconcataccepts either list-wrapped arguments (T[]) or top-level arguments (T):Here, (1) and (4) are top-level arguments (
T) whereas (2) and (3) are wrapped-arguments. Unfortunately, when you have a tuple or list type parameter, it's ambiguous whether an argument is list-wrapped or top-level:If
[[1,2], [3, 4]]is a top-level argument, then its type isnumber[][](or[number, number][]or [[number, number], [number, number]]). If it's a list-wrapped argument, then its type isnumber[](or[number, number]). But TypeScript can't tell, so it has to guess. Unfortunately, it guesses "top-level argument" (T) with typenumber[][]/[number, number][]. In the #9901 repro,number[][]is not compatible with the type argumentT=[number, number].Adding a stricter overload first guides the inference process to prefer the list-wrapped-only case (
T[]only) before falling back to the mixed top-level/list-wrapped overload.