Error: TS2300 Duplicate Identifier when having multiple web projects on the same solution referencing .d.ts files
Hi, I'm porting a "huge" solution which consists of more than one web application project on the same Visual Studio solution. The scenario is like this:
- a Visual Studio Solution consisting of multiple App Library projects and multiple websites, all using a mix of jquery/signalr/angularjs and so on client side libraries.
- the plain javascript portion of each website projects is going to be ported to TypeScript.
References to the same NuGet packages for .d.ts file for jQuery, SignalR and so on were added to every web application project.
Half of the times I open the solution I get 'TS2300 duplicate identifire' error on all those .d.ts files, building the solution as a whole is impossible. The error goes away if I unload all the website projects and I keep open just the one that I'm going to compile.
The obvious workaround is to create multiple solutions: one for each website, but it's a thing I would like to avoid if possible.
Anyone else has experimented something similar?
Thanks for any help. Alessandro
@AGiorgetti,
I believe it's possible to have a single solution with multiple projects, each a separate website.
Are there cross references amongst the projects? I mean using /// <reference> comments.
If there are library projects that are being shared in this way, then it is necessary to ensure duplicate definitions are not imported. It might be necessary, for example, to create a single project with just the JQuery definitions.
Hi @NoelAbrahams, Yes it is possible to have a single solution with multiple projects and most of the times it works. as for your question: No the projects do not share any cross reference (no /// reference to f.ts files that belongs to other projects).
I do not have problems on the .ts files I wrote myself, most of the problems come from the .d.ts files I download through NuGet; a situation similer to mine can be reproduced this way:
- create a solution
- add two web application projects
- on each project add some NuGet packages (like jquery.definitelytyped, angular.definitelytyped and so on)
- try to edit some .ts files in each project, at this point sometimes I start having 'duplicate identifier' errors on each .d.ts from the NuGet packages.
the only solution is 'unload' all the web application project but the single one I am working on.
I meant "one can have a single solution with multiple projects without having the duplicate identifier problem".
What particular error are you having? I mean what is being reported as a duplicate?
If we look at this from first principles, each project should have an isolated context, and identifiers do not leak across projects, unless there are explicit references via <reference>. It does sound like there are duplicates within the project. I would attempt to trace that down.
I'm getting the errors on the various 'jquery.d.ts', 'angular.d.ts', and so on... all the type definition files that belongs to the definitelytyped packages.
If I look at the content of jquery.d.ts:
interface JQueryAjaxSettings {
accepts?: any;
async?: boolean;
...
all the members in every interface will be marked with the TS2300 error
Can you share the commandline args for tsc.exe, you should find it in your msbuild log, just search tsc.exe?
Hi, here's what I can read from the msbuild log file
PreComputeCompileTypeScript: C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.5\tsc.exe --sourcemap --target ES5 --noEmitOnError --locale en-US COMPUTE_PATHS_ONLY [list of .ts files] CompileTypeScript: 2> C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.5\tsc.exe --sourcemap --target ES5 --noEmitOnError --locale en-US [list of .ts files]
all the files belongs to the correct website, no 'external' file are listed.
I've played a bit with the Visual Studio Settings (Tools - Options - Text Editor - TypeScript - Project) and It seems that a lot of my issues arise if I the flag 'Compile on Save - Automatically compile TypeScript files which are not part of a project' is checked. If I build the project from the command line or using some powershell/msbuild script I don't have any problem at all.
So to be clear, the errors do not show on build, they only show in VS, and they do not have a prefix "Build:" in the error text?
Can you enable your virtual project view and get me a snapshot of what you see. (feel free to email me directly if you do not want to share it publicly, my email: mhegazy at microsoft com). to enable the view go to tools\options\TextEditor\TypeScript\Project and check "Display Virtual Projects when a Solution is loaded". then reload your solution, you should find a new node in solution explorer called "TypeScript Virtual Projects", that is what i need to see.
Hi @mhegazy, yes that's what is happening, I cannot verify the "Build:" prefix because yesterday never happened. I've enabled the "Display Virtual Project" option, as soon as it happens again I'll post some screenshot to you.
OK I've spotted the problem, thanks to the 'Display Virtual Project' option I was able to identify a file that had a reference to other libraries .d.ts files in another project. That file was moved between projects and was the root of all evil.
I'm closing this because it's not an issue.
Thanks for the tip!
@AGiorgetti I had the exact same project scenario, made the exact same reference mistake, and used your exact same solution. Thank you!
It would be nice if Visual Studio showed you the files that it found the duplicates in.
Insead of:
Duplicate identifier 'foo'.
show:
Duplicate identifier 'foo' found in ['./Foo.ts', './Bar.ts']