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
It seems related to #10727, but that issue focuses on Object rest/spread, whereas this is specifically about tuples.
Use Cases
Typed tuples are part of the existing language. So it seems natural that one should be able to type rest arguments .
For example, if you want to represent a syntax tree, you might want to write:
typeFunCall=['FUNCALL',Symbol, ...Expression[]];// error in 2.9.1 :(typeSymbol=string;typeExpression=FunCall|Scalar;typeScalar=number|string|null;
But this isn't allowed in Typescript 2.9.1.
Examples
typeFoo=[string, ...number[]];constf1: Foo=["str",2,3,4];// should passconstf2: Foo=["str","2",3,4];// should fail: // "Type '(string | number)[]' is not assignable to type 'number[]'.constf2: Foo=["str",2,"3",4];// should fail:// "Type '(number | string)[]' is not assignable to type 'number[]'.constf1: Foo=[1,2,3,4];// should fail:// "Type 'number' is not assignable to type 'string'.
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript / JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. new expression-level syntax)
The text was updated successfully, but these errors were encountered:
@ahejlsberg, #24897 seems to deal with rest arguments to functions, whereas this deals with definition of tuple types with the rest operator. Does it makes sense to include tuple types in that issue?
Search Terms
tuple type rest spread typescript
Suggestion
I'd like to be able to write tuple types using the spread operator. For example:
Currently, this produces an error at the ellipsis: "Type expected".
Here is a question asking much the same thing on Stack Overflow: https://stackoverflow.com/questions/44934541/how-to-use-the-spread-operator-in-a-typescript-tuple
It seems related to #10727, but that issue focuses on Object rest/spread, whereas this is specifically about tuples.
Use Cases
Typed tuples are part of the existing language. So it seems natural that one should be able to type rest arguments .
For example, if you want to represent a syntax tree, you might want to write:
But this isn't allowed in Typescript 2.9.1.
Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: