In TypeScript, tuple types are fixed-length arrays where each index has a specific type:
type Pair<A, B> = [A, B]; // position 0 = A, position 1 = B
type Triple<A, B, C> = [A, B, C]; // position 0 = A, 1 = B, 2 = C
// Destructuring preserves types:
const [name, age]: [string, number] = ['Alice', 30];
// ^ string ^ numberThe difference from a plain array:
Array<string | number> — every element is string | number[string, number] — position 0 is string, position 1 is numberfunction zip<A, B>(as: readonly A[], bs: readonly B[]): Array<[A, B]>
function unzip<A, B>(pairs: ReadonlyArray<readonly [A, B]>): [A[], B[]]zip([1, 2, 3], ['a', 'b', 'c'])
// → [[1,'a'], [2,'b'], [3,'c']]
// TypeScript knows each element is [number, string] ✅
unzip([[1,'a'], [2,'b']])
// → [[1, 2], ['a', 'b']]
// TypeScript knows result is [number[], string[]] ✅Sample tests