TS1331
TypeScriptERRORNotableSyntaxHIGH confidence
A property of a class whose type is a 'unique symbol' type must be both 'stat...
Production Risk
Build will fail; resolve before shipping.
What this means
A syntax error (TS1331): A property of a class whose type is a 'unique symbol' type must be both 'static' and 'readonly'.. This diagnostic is emitted by the TypeScript compiler when a property of a class whose type is a 'unique symbol' type must be both 'static' and 'readonly'..
Why it happens
- 1Attempting to modify a property or variable declared as readonly
How to reproduce
TypeScript compiler reports TS1331 during type checking.
trigger — this will error
trigger — this will error
// Triggers TS1331 // A property of a class whose type is a 'unique symbol' type must be both 'static' and 'readonly'.
expected output
error TS1331: A property of a class whose type is a 'unique symbol' type must be both 'static' and 'readonly'.
Fix
Remove the readonly modifier or create a mutable copy
WHEN When you need to mutate a readonly property
Remove the readonly modifier or create a mutable copy
// Create a mutable copy
const mutable = { ...readonlyObject };
mutable.property = newValue;
// Or remove readonly from the type definition
type MyType = { property: string }; // not readonlyWhy this works
readonly properties enforce immutability at the type level; create a copy to modify.
Sources
Official documentation ↗
TypeScript Compiler Diagnostics
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev