- Error
- Reported by the type checker
TS2628
Cannot assign to '{0}' because it is an enum.
An enum's name is used as an assignment target. Enums can't be reassigned; assign to a variable instead.
What it means
The left side of the assignment is an enum declaration. An enum is a fixed set of values and its name can't be rebound.
Example
enum Mode { On, Off }
Mode = Mode;
export {};
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,1): error TS2628: Cannot assign to 'Mode' because it is an enum.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Use a variable of the enum type:
let mode: Mode = Mode.On; mode = Mode.Off;.