You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A tuple type with a rest element doesn't duck-type properly to the similar tuple type, although they are conceptually identical, causing a ts2345 error to show up when trying to use one with the other.
The type I tested was a type defining a non-empty array. It looks like there's a bug because the location of the "non-empty item" in the definition matters for typescript, although there shouldn't be any difference in the kind of arrays that are accepted for each type.
🔎 Search Terms
tuple
rest
🕗 Version & Regression Information
Since 4.2 where rest params where allowed a the start of a tuple too
This is the behavior in every version I tried, and I reviewed the FAQ for entries about tuple
While I can see that [T, ...T[]] and [...T[], T] effectively express the same concept (an array with at least one element), I'm not sure it is worth the extra complexity to detect and equate these types. If we did, we'd likely also have to detect and equate [T, T, ...T[]], [T, ...T[], T] and [...T[], T, T] and so on.
This isn't related to #49138 (which has to do with a missing contextual type).
Bug Report
A tuple type with a rest element doesn't duck-type properly to the similar tuple type, although they are conceptually identical, causing a ts2345 error to show up when trying to use one with the other.
The type I tested was a type defining a non-empty array. It looks like there's a bug because the location of the "non-empty item" in the definition matters for typescript, although there shouldn't be any difference in the kind of arrays that are accepted for each type.
🔎 Search Terms
🕗 Version & Regression Information
Since 4.2 where rest params where allowed a the start of a tuple too
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
🙂 Expected behavior
The text was updated successfully, but these errors were encountered: