TypeScript Types

Tuple types — positional contracts

A tuple records types at specific positions and can express required, optional or rest elements. A two-element tuple rejects an incompatible initializer length, unlike an ordinary array type. Mutable tuples still have array methods at runtime, and some mutations can invalidate the assumed positional shape. A readonly tuple is often a better API for a fixed record. Example output: "points:5". The example was designed for strict checking with an ES2022 target; type annotations do not add runtime validation.

Formal Syntax & Structure

typescript syntaxtypescript
type Pair = [string, number];

Working Example

Example Snippettypescript
const entry: [string, number] = ["points", 5];const [label, count] = entry;console.log(`${label}:${count}`);
TypeScript Reference