5

Is there a way to define variable-length Array tuple?

["string", 1, 1, 1, 1, 1]
["string", 1]

Something like

type StringNumbers = [string, ...number]
2
  • 5
    How about type StringNumbers = [string, ...number[]] Commented Jan 6, 2020 at 23:31
  • 1
    @TitianCernicova-Dragomir OMG, TypeScript type system would never stop surprising me, I was not expected that it's possible :). Thanks! Commented Jan 7, 2020 at 0:48

1 Answer 1

7

You can use rest in tuples:

type StringNumbers = [string, ...number[]] 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.