Dev Tools · 1h ago
TypeScript readonly arrays: shallow safety, deep pitfalls
TypeScript's readonly modifier only prevents top-level mutations, leaving nested objects mutable. Type widening can strip readonly from literals unless using as const. Deep immutability requires recursive types or as const, with tradeoffs in ergonomics and inference.
Meridian48 take
The article clarifies a common misconception but overstates the risk; for most UI code, shallow readonly is sufficient.
Read the full reporting
TypeScript `readonly` Arrays and Tuples: When Immutability Saves You and When It Fights You →
DEV Community
typescriptimmutability