-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Cannot redeclare block-scoped variable" in separate files with declaration of same name #47229
Comments
When you don't have a
So this is working as intended. |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow or the TypeScript Discord community. |
I have the same issue. It might be working as intended, but it's unclear how this needs to be configured in tsconfig. |
I stumbled on this issue as well, and it really feels like the following aren't working as intended in a tsconfig for node projects:
And that's adding a bit on top of the recommended config from here: https://www.npmjs.com/package/@tsconfig/node16 The best solution I found was to do one of two things: a) Add a useless export to the files that are not working, e.g. I suspect that doing the latter would make it easier to transition to ESM when they are no longer experimental. There's an added benefit if you're using the latest version of TS in that you can prefer exporting your interfaces right away, and lean on In the end, we're just straddling that awkward in-between space of ESM + CommonJS, so no solution will feel great. :) |
Change your import export statements from node style to ES style:
|
Is there a way to force TypeScript to see files without an |
you can set |
Bug Report
🔎 Search Terms
error TS2451: Cannot redeclare block-scoped variable
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about block-scoped variables and shadowing.
⏯ Playground Link
No playground link is available, since the bug is specific to behavior across multiple files.
💻 Code
package.json
tsconfig.json
index.ts
b.ts
c.ts
🙁 Actual behavior
JS files
index.js
,b.js
,c.js
are emitted and do produce the expected result, but at compile time, the following errors are thrown:Running
node index.js
does, indeed, yield9
.🙂 Expected behavior
Code compiles without error, since there is only one declaration of
c
per file.The text was updated successfully, but these errors were encountered: