-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Duplicate identifier error when naming a class 'Node' #16143
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
Comments
Because Node is already part of the global namespace and cannot be redeclared. It needs to be part of a module, so it is not part of the global namespace. |
That makes sense, thanks. Closing it now. |
What do you mean by "It needs to be part of a module"? I ran in to this exactly name collision, but I've got my class definition in a .ts file that is being loaded via import. My tsconfig.json has the module system set to "commonjs". |
You would need to provide more details. What does your module look like? If it doesn't have any This will error while this works: -class Node {
+export class Node {
} |
Whoa. I did not realize that. This particular module will have no imports and did not yet have any exports, since I had just started writing it. I wasn't planning to export the Node type, but was going to export some functions that used it. Thank you! |
As just discussed in #18232, if you need have something that you want to be considered a module without any export { } Which will end up being stripped when the module is emitted. |
TypeScript Version: 2.3.3
Node.js Version: 7.10.0
Code
Safe the file as
index.ts
and runtsc index.ts
. Notsconfig.json
.Expected behavior:
Compiles without error.
Actual behavior:
Compiler returns the following error:
Renaming the class makes it pass.
The text was updated successfully, but these errors were encountered: