Thuta Learning
IntermediateProgrammingintermediate

Tuples

Relax. We'll talk through this in plain words — no textbook voice.

Tuple is an array type that holds a fixed number of elements, where the type of each element is known.

typescript
// Declare a tuple type
let user: [number, string];

// Initialize it
user = [1, "Steve"];

// user = ["Steve", 1]; // Error: Type 'string' is not assignable to type 'number'.

console.log(user[1]);
You should see
Steve
Tuples | Thuta Learning