Confusing "duplicate identifier" Typescript error message
Update: Version 1.0 of Typings changed the output structure and the below answer relates to pre 1.0 version.
If you are using Typings and exclude in your tsconfig.json, you may run into the issue of duplicate types and need something like the following:
{
"exclude": [
"typings/browser.d.ts",
"typings/browser",
"node_modules"
]
}
To simplify integration with TypeScript, two files - typings/main.d.ts and typings/browser.d.ts - are generated which reference all the typings installed in the project only one of which can be used at a time.
So depending on which version you need, you should exclude (or include) the "browser" or the "main" type files, but not both, as this is where the duplicates come from.
This Typings issue discusses it more.
Problem was solved by simply:
- Deleting the
node_modules
folder - Running
npm install
to get all packages with correct versions
In my case, the problem occurred after changing Git branches, where a new branch was using a different set of node modules. The old branch was using TypeScript v1.8, the new one v2.0
This is because of the combination of two things:
tsconfig
not having anyfiles
section. From http://www.typescriptlang.org/docs/handbook/tsconfig-json.htmlIf no "files" property is present in a tsconfig.json, the compiler defaults to including all files in the containing directory and subdirectories. When a "files" property is specified, only those files are included.
Including
typescript
as an npm dependency :node_modules/typescript/
This means that all oftypescript
gets included .... there is an implicitly includedlib.d.ts
in your project anyways (http://basarat.gitbook.io/typescript/content/docs/types/lib.d.ts.html) and its conflicting with the one that ships with the NPM version of typescript.
Fix
Either list files
or include
explicitly https://basarat.gitbook.io/typescript/docs/project/files.html ð¹