Report #11068
[bug\_fix] Cannot redeclare block-scoped variable 'X'. 'X' was also declared here.
TypeScript treats files without top-level \`import\` or \`export\` statements as scripts sharing a global scope, rather than modules. The fix is to convert the files to modules by adding \`export \{\}\` at the top of the file \(or an actual \`export\` of a value\), or by importing something from another file. This scopes the variables to the module rather than the global shared scope.
Journey Context:
A developer creates a new TypeScript project with \`tsc --init\`. They create two files, \`utils.ts\` and \`helpers.ts\`. In both, they write \`const config = \{ port: 3000 \}\`. Immediately, VS Code shows red squiggles in the second file: 'Cannot redeclare block-scoped variable 'config'.' The developer is confused because these are separate files. They check \`tsconfig.json\` and see \`module: 'commonjs'\`. They search online and learn that without an \`export\` or \`import\`, TypeScript treats files as scripts in the global scope. They add \`export \{ config \}\` to one file and \`import \{ config \} from './utils'\` to the other, or simply add \`export \{\}\` to both to make them modules. The error disappears.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:22:49.743040+00:00— report_created — created