`Tuple & nominal` not recognised as tuple in spread parameter
See original GitHub issueBug Report
🔎 Search Terms
Nominal, Spread, Tuple,
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about spread and intersections
⏯ Playground Link
Playground link with relevant code
💻 Code
declare let a: [number, number, number] & { _nominal_a: never }
function b(...params: [number, number, number]) {}
b(...a) // Error: A spread argument must either have a tuple type or be passed to a rest parameter.
🙁 Actual behavior
The error in the code example is thrown, because TypeScript does not detect it as being a tuple. In roblox-ts, we use a nominal marker type to indicate a special kind of tuple. This bug means that this tuple type can then not be spreaded into a fixed argument function. Our issue: https://github.com/roblox-ts/roblox-ts/issues/1537
🙂 Expected behavior
This is a tuple type, and should therefore be recognised as such.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:6
Top Results From Across the Web
A spread argument must either have a tuple type or be passed ...
I have errors: A spread argument must either have a tuple type or be passed to a rest parameter. Can someone can help...
Read more >Documentation - TypeScript 3.0
Tuples in rest parameters and spread expressions. TypeScript 3.0 adds support to multiple new capabilities to interact with function parameter lists as tuple...
Read more >Returning Multiple Values Using Tuples in C# - dummies
In versions of C# prior to C# 7.0, every return value was a single object. It could be a really complex object, but...
Read more >Java 14 Feature Spotlight: Records - InfoQ
A record can be best thought of as a nominal tuple; it is a transparent ... Specifically, they are not intended as a...
Read more >Google TypeScript Style Guide
Do not use the opt_ prefix for optional parameters. ... This can be used to name primitives, unions, tuples, and any other types....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This usually makes sense, because you don’t know the Array’s length, which is why it’s (as the correct behaviour) not considered a tuple. That’s part 1, and then part 2, I believe this not working in this case is a separate missing behaviour, which is that normal parameters need to be filled manually, not being considered to be part of the rest parameter. What I mean by that is that a function like
a(obj: object, ...other: object[])
will not allow a call likea(...objects)
whereobjects
isArray<object>
, despite this being type-compatible.I am not sure if this is related, or supposed to occur… However, when attempting to brand or flavor a tuple it appears that TypeScript is no longer able to restrict property access past the length of the tuple.
Example
Playground Link
It appears that the expansion of the type includes
[x: number]: number
. Maybe I should open this a separate issue?