Contextually allow spread to create tuples from tuples #33783
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Search Terms
tuple spread
Suggestion
Right now, I cannot create a 3-tuple from a 2-tuple using spread, like so:
But to me it seams that, given the expected type, TypeScript would be able to see that spreading a
[number,number]
and adding astring
would create a[number, number, string]
.Use Cases
Right now to produce a correct type B, given a value of type A, I would need to destructure and recreate the type:
Which works for simple tuples like this, but does not scale well.
Examples
I was working on a piece of code that looked like this:
I then needed to expand the result of majorOperation to include another result, not produced by
minorOperation()
, so I split the result type in two and expected typescript to allow me to combine them using spread:Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: