readonly — is the object immutable at runtime?
Answer out loud or in your head first, then compare.
Answer
readonly blocks assigning to a property through that typed reference. It doesn't freeze the object at runtime and isn't deep by default.
TypeScript
interface Settings {
readonly id: string;
nested: { theme: string };
}
const settings: Settings = { id: 's1', nested: { theme: 'light' } };
// settings.id = 's2'; // TypeScript error
settings.nested.theme = 'dark'; // allowedTo be precise: Readonly<T> is shallow too. Object.freeze works at runtime, but it also only freezes the object's own properties.
Pitfall: readonly is a usage contract in the types, not full protection against mutation through another alias.
How did it go? Be honest — “Not yet” puts the question on your review list.
Related questions
- What does readonly really do? — TypeScript