Common causes
- Reassigning a property declared as readonly in an interface or class
- Mutating an object created with as const, which makes all properties deeply readonly
- Modifying a property on an object typed as Readonly<T> or using Object.freeze()
- Trying to reassign a class constructor parameter marked as readonly
How to fix it
- Remove the readonly modifier if the property should be mutable
- Create a new object instead of mutating: const updated = { ...original, property: newValue }
- If using as const, only use it when you intend the object to be immutable
- Use a mutable copy: const mutable = { ...readonlyObj } to get a writable version
Example
interface Config { readonly baseUrl: string; }
const config: Config = { baseUrl: 'https://api.example.com' };
config.baseUrl = 'https://other.com';
// error TS2540: Cannot assign to 'baseUrl' because it is a read-only property.Reassigning a readonly interface property after the object has been initialized
Browse more errors
The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.
