- Error
- Reported by the type checker
TS2629
Cannot assign to '{0}' because it is a class.
A class name is used as an assignment target. Class declarations can't be reassigned; use a variable if you need to swap classes.
What it means
The left side of the assignment is a class declaration. A class declaration's name can't be rebound.
Example
class Store {}
Store = class {};
export {};
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,1): error TS2629: Cannot assign to 'Store' because it is a class.
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 that holds the class:
let Impl: typeof Store = Store;and reassign that. - Or rename the new class.