TypeScript: Duplicate identifiers
I’m having an issue with duplicate identifier errors. It appears to stem from having the same definitions listed in multiple places.
Let’s say that I have a simple node server that utilizes the bluebird promise library. I have bluebird used in the main server code and in a library I wrote used by the server code. The structure looks like this:
|-- server.ts
|-- tsd.json
|-- typings
|-- lib
|-- mylib.ts
|-- tsd.json
|-- typings
Here is the code for and for mylib.ts:
/// <reference path="./typings/tsd.d.ts"/>
import Promise = require('bluebird')
class MyLib {
}
export = MyLib
and server.ts:
/// <reference path="./typings/tsd.d.ts"/>
import Promise = require('bluebird')
import MyLib = require('./lib/mylib')
class Server {
}
export = Server
As you can see, both server.ts and mylib.ts use the bluebird library. Since server.ts uses mylib.ts, it ends up importing bluebird twice, which results in errors. So when I run
tsc server.ts --module commonjs
I get
lib/typings/bluebird/bluebird.d.ts(705,9): error TS2300: Duplicate identifier ‘concurrency’. lib/typings/bluebird/bluebird.d.ts(708,9): error TS2300: Duplicate identifier ‘spread’. lib/typings/bluebird/bluebird.d.ts(711,9): error TS2300: Duplicate identifier ‘suffix’. typings/bluebird/bluebird.d.ts(705,9): error TS2300: Duplicate identifier ‘concurrency’. typings/bluebird/bluebird.d.ts(708,9): error TS2300: Duplicate identifier ‘spread’. typings/bluebird/bluebird.d.ts(711,9): error TS2300: Duplicate identifier ‘suffix’.
Tools like npm seem to be able to handle this situation. The only way I can get typescript to handle it is by having a single tsd.json file and corresponding typings folder at the root of my project and having all the typescript definitions live there. Is that the generally accepted way to structure things?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 22 (10 by maintainers)
@born2net I didn’t understand how you solved it, can you please give some more details ?
+1 + 1 + 1… please add ignoreDups flag
I beleive the issue has to do with the trasnpiler not respecting the exclude as in:
since as you can see from my attached image, all issues are a result of the TS still inspecting the node_modules dir
looks like phantom js & node typings are conflicting figure it’s related to this issue
“exclude” only excludes files in your folder, and its subfolders from being automatically included int he compilation. if you import a module in your code, the compiler will have to pull it in (e.g.
import {..} from "angular2\angular2"). if you want to disable this use–noResolve`.can you share your project so that i can understand the project setup?