Alex Craft
Alex Craft

Reputation: 15336

Variable length Array tuple in TypeScript?

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

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

Something like

type StringNumbers = [string, ...number]

Upvotes: 5

Views: 1188

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 249576

You can use rest in tuples:

type StringNumbers = [string, ...number[]] 

Upvotes: 7

Related Questions