Tuples
TypeScript โฉ
Variadic Tuple Types (โณ๏ธ TS 4.0)
Labeled Tuple Elements (โณ๏ธ TS 4.0)
A tuple type is a sort of Array type that knows exactly how many elements it contains, and exactly which types it contains at specific positions.
Cheatsheet
Optional elements
can only come at the end
affect the type of length
Rest elements
Tuples can have rest elements, which have to be an array/tuple type.
A tuple with a rest element has no set โlengthโ - it only has a set of well-known elements in different positions.
Tuples types can be used in rest parameters and arguments, so that the following:
is basically equivalent to:
Variadic Tuple Types
Labeled Tuple Elements
Last updated