...

/

Tuple For Type and Length Arrays

Tuple For Type and Length Arrays

In this lesson, we will discuss tuples and how TypeScript differentiates them from arrays.

Tuple syntax #

The tuple type is an array of defined elements. To declare a tuple, you use square brackets, as in line 1, but instead of specifying a value, you use a type.

Press + to interact
let numberTuple: [number, number, number];

A tuple can handle many different types. The tuple uses the same syntax as other types.

Press + to interact
let myTupleWithTwoTypes: [number, string];

There is no difference between the declaration of a variable and the assignment. TypeScript checks for ...