Tuples as Records
A tuple can stand in for a small record: a fixed list of fields identified by position (and, optionally, by a label). Use it when order is the API. Prefer a named object when the fields have independent meaning.
Detailed Explanation
A record is a bundle of named fields. A tuple is a bundle of ordered slots. TypeScript lets you treat the second as the first when the slots are the fields: [id: string, cents: number] is a two-field record whose names exist only in the type.
Labels do not exist at runtime and do not participate in assignability. [id: string, cents: number] and [string, number] are the same type. The labels show up in editor hovers and in destructuring hints. They are documentation the compiler displays, not properties you can pair.id.
The cases where a tuple-as-record is the honest type:
- A function that returns two things (
[error, value],[start, end], React's[state, setState]). - A map entry (
[K, V]) fromMaporObject.entries. - A row from a CSV or a positional SQL driver, before you name the columns.
- A rest argument list (
Parameters<F>is a tuple).
The cases where it is a mistake:
- A user object with
emailandid— names matter, order should not. - Anything you will spread into a public JSON API. Objects survive key-based evolution; tuples break when you insert a slot at the front.
readonly [string, number] is the immutable view. as const on a literal pair produces that plus literal element types. Destructuring is how you recover names at the value level: const [id, cents] = row. The names you choose there are yours; they do not have to match the type labels.
A tuple record still has array methods. row.push(1) is a type error on a fixed-length tuple, which is what you want. row.map widens to an array and forgets the slot types. Treat tuples as records, not as lists you iterate.
When a tuple grows past three slots, it has usually become an object that nobody renamed. Stop and write an interface. The type system will not stop you from writing [string, string, string, string, number]; readers will.
Code Examples
1. A labeled pair as a return type.
// 1. A labeled pair as a return type.
type ChargeRow = [id: string, cents: number];
function charge(cents: number): ChargeRow {
return ["ch_1", cents];
}
const [id, amount] = charge(1999);
console.log(id, amount); // ch_1 19992. Map entries are tuples; name them when you iterate.
// 2. Map entries are tuples; name them when you iterate.
const totals = new Map<string, number>([["usd", 1999]]);
for (const [currency, cents] of totals) {
console.log(currency, cents);
}3. Prefer an object once names matter more than order.
// 3. Prefer an object once names matter more than order.
type Charge = { id: string; cents: number };
function asCharge(row: ChargeRow): Charge {
const [id, cents] = row;
return { id, cents };
}Common Gotchas
Labels are not properties
`row.id` is a type error. Destructure or index.
Inserting a slot is a breaking change for every caller
objects can grow a new optional field. Tuples cannot grow in the middle without shifting types.
`[string, number]` is assignable to `readonly [string, number]`, not the reverse
same rule as arrays.
`Object.entries` is `[string, T][]`, not `[keyof T, T[keyof T]][]`
extra keys and `string` widening make a precise tuple record unsafe without a helper.