more of an aspiration than a claim

TypeScript Duplicate Identifier and Typings

If your TypeScript tsconfig.json is using “exclude” and Typings for your TypeScript definitions, you may run into duplicate identifier warning messages.

error TS2300: Duplicate identifier

This warning means you are probably including multiply copies of the same file, or a file is redefining the same definitions.

Typings currently creates definitions for ‘main’ and ‘browser’. For a front-end package Typings suggests you are going to want the ‘browser’ types as they have browser field overrides. There was also an issue to remove creation of both browser and main versions, but currently a desired alternative has not been implemented.

Due to a lack of file globbing support, I tried changing to using “exclude” in my tsconfig.json. This means I don’t individually list each item under “files”, but every TypeScript file is included, apart from those files and directories I explicitly “exclude”.

Soon after I noticed I was getting the duplicate identifier issues. Turns out the solution was already on the home page.

I found a similar question about duplicate identifiers here, so I added my own answer.

Basically you need to exclude the files you don’t want to use from the Typings directory, eg:

{
  "exclude": [
    "typings/browser.d.ts",
    "typings/browser",
    "node_modules"
  ]
}