- Error
- Reported by the type checker
TS2631
Cannot assign to '{0}' because it is a namespace.
A namespace name is used as an assignment target. Namespaces can't be reassigned; change their members instead.
What it means
The left side of the assignment is a namespace. A namespace's name can't be rebound.
Example
namespace Config { export const debug = false; }
Config = Config;
export {};
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,1): error TS2631: Cannot assign to 'Config' because it is a namespace.
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
- Change members of the namespace instead, or use an object in a
letvariable if the whole value needs replacing.