Error AtlasError Documentation and Resolution

Cannot assign to read only property

Cannot assign to '{0}' because it is a read-only property.

TypeScript rejected an assignment because the target property is marked readonly.

TS2540build
Cannot assign to '{0}' because it is a read-only property.
  • Code attempts to modify a property declared with readonly.
  • A library type exposes an immutable object shape.
  • A function mutates input values that were intentionally typed as readonly.
  1. Stop mutating the readonly property directly.
  2. Create a new object with the updated value instead of changing the existing one.
  3. Review the type definition and remove readonly only if mutation is genuinely intended.
TypeScript Handbook: Object Types
TS2540 Cannot assign to read only property: causes and fixes | Error Atlas