How do you type a fixed-length tuple vs an array? Show named tuple members, a rest element, and `readonly` arrays — and why readonly matters.
Precise array/tuple typing and using readonly to prevent mutation at the type level.
An array type `T[]` (or `Array<T>`) is homogeneous and any length; a tuple `[string, number]` fixes BOTH the length and the type at each position — index 0 is a string, index 1 a number. Tuples can name elements for readability (`[first: number, second: number]`; the names are documentation only, erased at runtime), mark trailing elements optional (`[number, number?]`), and use a rest element to capture 'the rest' (`[string, ...number[]]`) — which is exactly how variadic function parameter lists are typed. `readonly` makes an array/tuple immutable at the type level: `readonly number[]` (or `ReadonlyArray<number>`) removes push/pop/splice and index assignment from the type, and `readonly [a, b]` freezes a tuple. This is compile-time only — nothing is frozen at runtime (that's `Object.freeze`) — but it's how you promise a function won't mutate an array it's handed, and it's what `as const` produces. A readonly array is deliberately NOT assignable to a mutable one (that would let a callee mutate it), which is the safety the modifier buys. Reach for tuples for fixed heterogeneous data (a `useState`-style [value, setter] pair, coordinates, key/value entries) and readonly for any array you pass around but don't own.
Typing [value, setter] hook returns, coordinate pairs, Object.entries results, and function args you promise not to mutate (readonly).