TypeScript: Duplicate identifier error for d.ts files in Visual Studio 2017
TypeScript Language Version: 2.2 Visual Studio Typescript tooling Version 2.1.5
I am having trouble with typescript errors like TS2300: duplicate identifier ‘export=’ and TS2374: Duplicate string index signature. This errors appear in error window, but projects builds successful. This errors appear only with VS2017.
Env Details:
-
Type definitions are installed via nuget to default folder: project root/scripts/typings/
-
For build I use nuget package Microsoft.TypeScript.MSBuild" version="2.2.1
-
tsconfig is NOT used**, instead here are setting from csproj:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptJSXEmit>None</TypeScriptJSXEmit>
<TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
<TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
<TypeScriptRemoveComments>False</TypeScriptRemoveComments>
<TypeScriptOutFile>
</TypeScriptOutFile>
<TypeScriptOutDir />
<TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
<TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
<TypeScriptSourceMap>True</TypeScriptSourceMap>
<TypeScriptMapRoot />
<TypeScriptSourceRoot />
<TypeScriptStrictNullChecks>false</TypeScriptStrictNullChecks>
<TypeScriptNoFallthroughCasesInSwitch>true</TypeScriptNoFallthroughCasesInSwitch>
<TypeScriptLib>dom,es5,es2015.promise</TypeScriptLib>
</PropertyGroup>
I assume I see this errors because VS2017 somehow downloaded @types to this folder: ~\AppData\Local\Microsoft\TypeScript\node_modules@types\ and there is conflict between this types definitions and those types installed via nuget, if this is the cause I am not sure how disable this feature in VS2017 and honor only nuget installed d.ts?
I would appreciate any help to this issue.
Here is screenshot:

About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 14
- Comments: 96 (19 by maintainers)
I upgraded to 15.1 (26403.0) today and I still get the errors…
I was just about to add a new issue but I believe this is the same issue I am having. I have managed to replicate it in a simple project (our production project is much more complicated and uses nuget but still suffers from the issue).
To reproduce:
I have used each RC build of VS2017 and i can say it was fine until the very last RC (which i think was using the TS2.2 plugin) which i was hoping would be fixed in the release but can confirm i get it in the release as well. This is only for design time as compile time is always correct.
My speculation is that visual studio plugin is sourcing it’s own list of files to run through the language service which includes definition files it generates. I have also had it pull .d.ts files from the gulp-typescript package inside a node_modules folder which was listed as exclude in the tsconfig.json.
Any more information required let me know as I have a few cases where this is an issue.
@mhegazy Please reopen this issue, it is still a problem.
The latest VS Preview (https://www.visualstudio.com/en-us/news/releasenotes/vs2017-Preview-relnotes#15.2.26412.01) includes SxS support for TypeScript versions, and should fix most of the above issues also. By end of week (or early next week) the Preview will be updated again to (hopefully) address all the issues outlined above.
There were a couple of factors impacting VS here. One was the issue @mhegazy fixed above around semantic errors in JS files, and another just recently discovered that @zhengbli fixed with #15080 where the project structure was getting confused. Apologies for the pain & frustration these have caused.
@ManuelHaas If you can send it to billti at microsoft dot com, then I’ll take a look. Reopening while investigating…
Quick and dirty hack to get around this while waiting for a proper fix:
%localappdata%\Microsoft\TypeScript\package.json. Mine currently looks like:%localappdata%\Microsoft\TypeScript\package.jsonread-only.%localappdata%\Microsoft\TypeScript\node_modules\@typesAfter a VS restart, clean, rebuild everything is back to normal (for me at least).
Still happens in 26403.3 as well.
RESOLVED BY BELOW STEPS I got errors related to d.ts and duplicate identifier errors while deploying my application. I opened containing Folder - properties - removed read only option in the bottom. Clicked on Apply and OK. Restarted visual studio , opened solution , clean,build and published again . And all errors related d.ts cleared off. Hope this helps someone.
Thanks @ManuelHaas . I got the project and can see the problem.
In your case it’s because the knockout definitions are indeed included twice. Here’s why.
In your solution folder (one up from the project) you have a
node_modulesfolder containing the@types\knockoutpackage. So when your project opens and the TypeScript project is created, and it sees theimport * as ko from "knockout";in the source file, it walks up looking for anode_modules\@types\knockoutfolder, sees this, and includes the knockout definitions.However in the
tsconfig.jsonfor your project you also have"typeAcquisition": {"enable": true}, which means it will go fetch the type definitions for the libraries it detects in use and include them. It sees knockout being used, so it goes fetches the knockout library into the cache. Thus, two distinct copies of the knockout definitions are included, leading toduplicate...errors.There are a few ways you can fix this:
@types\knockoutNPM package you have in your solution - but I’m guessing the TypeScript project uses this."typeAcquisition"settings, add the entry"exclude": ["knockout"]- this way it won’t go automatically acquire this package again.Arguably we should also not go fetch & include a type definition for a package we already are including from under one of the type root (CC @RyanCavanaugh ).
The problem is reproduced when I open a project from a directory with junction to another drive (mklink /J command). If I create junction from D: to C:, Visual Studio shows me duplicates in same file:
I was encountering this extremely annoying error recently and setting “typeAcquisition”: {“enable”: false} fixed it. I am only using TypeScript to process .ts files with plain es5 code in an MVC5 project. I don’t see how this is still an issue a year after this was first reported.
Fix available; PR pending soon
There are actually two issues here:
knockoutto be an unresolved module during cached program rebuilds. PR up soonnodeto the ATAincludelist even though there may be a local@types/nodepackage in the project folder. The workaround is simple; just add"exclude": ["node"]to thetypeAcquisitionblock in your tsconfig. Logged #20402@mhegazy @billti I create a project with which the bug can be reproduced. How can I send it to you?
Still typescript Errors Version 15.2 (26430.12) visual studio 2017 Duplicate identifiers
nh43de
This happenes during build too. I’m developing core mvc app keeping some scripts in Views directory, and they are copied to output directory (with corresponding property being set) after build. So they stay in Debug and Release directories.
This problem can be solved by setting output in project settings outside project directory or by calling rmdir command after build event. But not publishing problem, which includes ts files in any directory. PubTmp creates after rmdir and it is always in obj\ .
Laguage service is scanning whole project folder for .ts files. It should ignore output folders for each configuration and “obj” folder. Or it should scan only ProjectItems in IDE, ignoring files that are not included in project tree.
I have found adding a typescript config file to the root of my project fixes Duplicate Identifiers found in the nuget jquery typings and the typings that is buried somewhere in my home folder.
It seems these are not solutions but work arounds and hacks. I found that turning off the Type Script compiler in the VS Solution files is good also but Microsoft should be fixing this issue to be honest.
Here is a link for you to maul over: Typescript compiler disabled-> https://github.com/Microsoft/TypeScript/issues/2294
@jjoekoullas you make my day)) I’ll try it asap
@odrozd sorry, forgot to mention to make
%localappdata%\Microsoft\TypeScript\package.jsonread-only@mhegazy Thanks for the quick fix! Is there a workaround while we are waiting for the fix to be released?