-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[error TS2300: Duplicate identifier] Global references #1039
Comments
@br1anchen loops in the reference graphs are still allowed. the example you have should still work in 1.1.0.1. There can be something else that is causing your issue. can you give a try with the latest in master? it will report you the errors on all instances of the duplicate definition. |
I've the same problem (Verified with master). I've a common file where all TypeScript references are included ( // FieldManager.ts
/// <reference path="../../../typings/tsd.d.ts" />
class FieldManager {
...
} // tsd.t.ts
/// <reference path="../src/ts/Manager/FieldManager.ts" />
... Error message when compile
|
I see it now thanks @Maks3w for the additional info. so the problem is how the compiler does relative path computation. if you give the compiler relative paths, it will not turn them to absolute, so it will just use ..\ to move up if needed. the result is that the same file can have more than one relative paths. and then included multiple times. A workaround for now, is either you call the compiler from your root folder ("src" in the above example) or just use absolute paths for files passed on the command line compiler. This fails:
Absolute path, works
Relative path to the root works
At the root directory works
|
@mhegazy Thanks for providing workarounds. Passing absolute path to TypeScript compiler works fine. I'm just wondering if it is safe enough to enable this behavior by default in WebStorm (I'm maintaining WebStorm TypeScript transpiling)? Will it work with previous versions of TypeScript compiler? Thanks. |
Hi, Thanks for @mhegazy and @Maks3w . Relative path is the problem. @segrey : I am using TypeScript transpiling file watcher in my project. After @mhegazy work around solution: I think it is ok to use |
My master ts file is not in the root, but down a couple of levels. In Webstorm I had to change the Working Directory to |
So to clarify, the is the recommended approach to have one giant |
Yeah this is far from fixed... it shouldnt throw this error for reference paths |
@davidleureka and @EBMike this issue has been closed over a year now. I am finding hard to understand the context between your comments and the original issue. please file a new ticket and include relevant details. |
Hi,
I just updated the typescript compiler from 1.0.1.0 to 1.1.0.1.
Then when I using the Webstorm Typescript Transpiling, it keeps reporting TS2300: Duplicate identifier.
I investigate a bit, it seems like the references is the problem.
In our current project, we include all the .ts files and external library .d.ts files in one references.d.ts file and include a single references.d.ts file for each .ts file we coded.
This reference mechanism works just fine on tsc 1.0.1.0
But on 1.1.0.1, it seems like it can not do self reference any more. Then I try to make specific reference for each .ts file. However it still get some TS2300: Duplicate identifier in some classes when the dependencies depend on another same dependency. It seems like it will reference the same dependency twice to cause Duplicate identifier error.
eg:
Because I am using AngularJS framework, so it is quite common that A and B are services to inject D service, C as controller to inject A and B services.
In this scenario, typescript compiler report TS2300: Duplicate identifier 'D' when it compile C.ts
PS: I know this references issue will not occurs in VS since it has some 'magic' implicant reference mechanism to reference all the .ts/ .d.ts files. I hope it is not the Webstorm issue, because it seems like compile issue more or less.
Also, it will be great if there is some standard Typescript coding style to do the proper dependencies reference when people are using Webstorm or other IDE than VS. Maybe some auto fixing dependencies reference as plugin would be better.
The text was updated successfully, but these errors were encountered: