Skip to content

Dependency on @types/* can cause conflict in type definition resolution (Duplicate identifier for @types/node) #5

Closed
@sompylasar

Description

@sompylasar

https://github.com/KingHenne/custom-tslint-formatters/blob/f2376dfe122b0b03d96b55a7c70e6bffa26ea4ce/package.json#L36-L37

  "dependencies": {
    "@types/chalk": "^0.4.31",
    "@types/node": "^7.0.12",

When custom-tslint-formatters is used as a dependency of a module with npm-shrinkwrap.json that is required by a TypeScript module for Node which itself depends on @types/node, the @types/node get installed twice into node_modules (using npm@3).

When building the TypeScript module, having more than one @types/node of the same version causes a ton of errors about duplicate identifiers because TypeScript gets two definitions for the global Node symbols.
Here's a sample of these errors with both conflicting paths visible:

node_modules/@some-company/ts-build-tools/node_modules/@types/node/index.d.ts(4283,18): error TS2300: Duplicate identifier 'Protocol'.


118 type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "latin1" | "binary" | "hex";
         ~~~~~~~~~~~~~~

node_modules/@types/node/index.d.ts(118,6): error TS2300: Duplicate identifier 'BufferEncoding'.


289     export class EventEmitter {
                     ~~~~~~~~~~~~

In this example, @some-company/ts-build-tools depends on custom-tslint-formatters and has npm-shrinkwrap.json, so npm ls looks like this:

├─┬ @some-company/ts-build-tools@1.0.0
...
│ ├─┬ custom-tslint-formatters@2.1.0
│ │ ├── @types/chalk@0.4.31
│ │ └── @types/node@7.0.38
...
├── @types/node@7.0.38
...

Related issue (with no solution as of now): microsoft/TypeScript#6496

The only workaround for now is to ensure only one declaration is installed, but this is impossible for packages that are dependencies.

As this package does not export any typings, these @types/ dependencies could be moved to devDependencies to avoid such behavior until the root issue is resolved within TypeScript compiler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions