readonly prevents reassignment of properties. ReadonlyArray<T> blocks mutating methods like push.
Immutability in APIs
Expose readonly arrays from functions so callers cannot mutate internal state. Optional properties model “may be absent” distinct from “present but undefined” when exactOptionalPropertyTypes is enabled.
Readonly at compile time does not freeze deep object graphs—nested fields may still be mutable unless you use deep readonly patterns.
Self-check
- What breaks if you call
pushon aReadonlyArray<string>?
Practice: Apply optional-readonly in the playground, then explain optional readonly in one sentence without looking at notes.