- Error
- Reported by the binder
TS2451
Cannot redeclare block-scoped variable '{0}'.
A let, const or class name is declared twice in the same scope. Rename one of them, or remove the duplicate.
What it means
Block-scoped declarations (let, const, class) can't share a name with another declaration in the same block. In script files (without imports or exports) the top-level scope is shared by every script, so the duplicate can be in another file.
Example
export {};
let user = "ada";
let user = "grace";
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'user'.
index.ts(3,5): error TS2451: Cannot redeclare block-scoped variable 'user'.
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
- Rename one of the variables, or reassign instead of redeclaring:
user = "grace". - If the clash is across script files, make the files modules by adding an
importorexport.