I have VS solution that has multiple projects.
There is a ProjectA that imports jquery and knockout and ProjectB that imports class from ProjectA and also imports knockout and jquery.
When I compile the solution (or projectB) in VS 2015 Update 3 with TS 2.0.6 installed I get the below errors.
2>D:\Temp\TSProject\TSProjectA\node_modules\@types\jquery\index.d.ts(623,5): error TS2374: Build:Duplicate string index signature.
2>D:\Temp\TSProject\TSProjectA\node_modules\@types\jquery\index.d.ts(2872,5): error TS2374: Build:Duplicate string index signature.
2>D:\Temp\TSProject\TSProjectA\node_modules\@types\jquery\index.d.ts(2873,5): error TS2375: Build:Duplicate number index signature.
2>D:\Temp\TSProject\TSProjectA\node_modules\@types\jquery\index.d.ts(3246,5): error TS2300: Build:Duplicate identifier 'export='.
2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(8,5): error TS2374: Build:Duplicate string index signature.
2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(14,5): error TS2374: Build:Duplicate string index signature.
2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(18,5): error TS2374: Build:Duplicate string index signature.
2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(38,5): error TS2374: Build:Duplicate string index signature.
2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(160,5): error TS2374: Build:Duplicate string index signature.
2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(682,2): error TS2300: Build:Duplicate identifier 'export='.
2>D:\Temp\TSProject\TSProjectMain\node_modules\@types\jquery\index.d.ts(3246,5): error TS2300: Build:Duplicate identifier 'export='.
2>D:\Temp\TSProject\TSProjectMain\node_modules\@types\knockout\index.d.ts(682,2): error TS2300: Build:Duplicate identifier 'export='.
I have attached a simplified solution where the issue is reproducible.
Seems to be related to issue #10968.
this looks like the same issue as https://github.com/Microsoft/TypeScript/issues/6496.
The declaration files for Jquery and knockout are declared in the global scope. this means that there is only one of them that can exist at a time. this results to conflicts once two files exist on disk.
The correct fix is to update the declaration files to be authored as modules instead of global, since they are rely not global.
as a workaround, you can add a path mapping entry in your tsconfig.json to make sure the second set of files are never loaded.
// TSProjectMain/tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"lib": [ "dom", "es2015.promise", "es5", "scripthost" ],
"module": "amd",
"moduleResolution": "node",
"noImplicitAny": true,
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"target": "es5",
"baseUrl": "./",
"paths": {
"*" : ["../TSProjectA/node_modules/@types/*", "./node_modules/@types/*", "*"]
},
"types": []
}
}
Alternatively, do not install @types\jquery in your second project, since your first project adds them already.
Add a _'paths'_ section to my _tsconfig.json_ worked perfectly for me.
Most helpful comment
this looks like the same issue as https://github.com/Microsoft/TypeScript/issues/6496.
The declaration files for
Jqueryandknockoutare declared in the global scope. this means that there is only one of them that can exist at a time. this results to conflicts once two files exist on disk.The correct fix is to update the declaration files to be authored as modules instead of global, since they are rely not global.
as a workaround, you can add a path mapping entry in your tsconfig.json to make sure the second set of files are never loaded.
Alternatively, do not install
@types\jqueryin your second project, since your first project adds them already.