TypeScript `readonly` Arrays and Tuples: When Immutability Saves You and When It Fights You
TL;DR AI
2 min readKey summary
TypeScript readonly arrays and tuples block reassignment and top-level mutation methods, but they do not make nested objects immutable.
The article compares readonly T[] with ReadonlyArray<T>, and shows how type widening can strip readonly during function calls.
Using readonly incorrectly can create a false sense of safety: nested data may still change even when the container looks protected.
When true deep immutability is needed, patterns like as const or DeepReadonly are worth using, but only with clear tradeoffs in mind.
