Skip to content

Duplicate identifier error when dependent project supplies its own type definitions for a shared library #10968

@mattyork

Description

@mattyork

TypeScript Version: 2.0.2

  • I have two directories containing typescript projects: proj1, proj2.
  • Both projects depend on React, and definitions are installed for each through npm install @types/react
  • They compile independently.

image

The problem: I get a "duplicate identifier" error when compiling proj2:

  • when the compiler processes a proj2 file it resolves module 'react' to proj2's proj2/node_modules/@types/react. All good.
  • when the compiler processes a proj1 file it resolves 'react' to proj1/node_modules/@types/react which would be fine, and hits the duplicate identifier error

Simplified Repro:

  1. Unzip bugreport.zip
  2. cd bugreport/proj1
  3. ./node_modules/.bin/tsc
  4. cd ../proj2
  5. ./node_modules/.bin/tsc

Expected behavior: succeeds. All is good.

Actual behavior:

../proj1/node_modules/@types/react/index.d.ts(7,21): error TS2300: Duplicate identifier 'React'.
index.ts(4,17): error TS2345: Argument of type 'typeof Proj1Comp' is not assignable to parameter of type 'ReactElement<{}>'.
  Property 'type' is missing in type 'typeof Proj1Comp'.
node_modules/@types/react/index.d.ts(7,21): error TS2300: Duplicate identifier 'React'.

How are we supposed to handle these situations where a dependency brings its own type definitions for a shared library?

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions