Skip to content

Duplicate identifiers #6475

Closed
Closed
@davidleureka

Description

@davidleureka

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions