Tuple
In one line
A tuple is an array type with a fixed number of elements where each position has a specific, potentially different type.
In simple words
A tuple is an array with a fixed length and specific types at each position. For example, [string, number] is a 2-element array where the first must be a string and the second must be a number.
Tuples differ from regular array types: string[] is an array of any length containing strings, while [string, number] is exactly 2 elements with specific types at each index.
Tuples are useful for returning multiple values from a function, representing coordinate pairs, and defining CSV row structures. TypeScript also supports rest elements in tuples, like [string, ...number[]] for a string followed by any number of numbers.
Example
let pair: [string, number] = ["age", 25];
console.log(pair[0]); // "age"
console.log(pair[1]); // 25The tuple has a string at index 0 and a number at index 1.
Related terms
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.