react-hooks-testing-library: Duplicated identifier Errors with TypeScript

  • react-hooks-testing-library version: 1.0.4
  • react-test-renderer version: 16.8.6
  • react version: 16.8.17
  • @types/react version: 16.8.17
  • typescript version: 3.3.3333
  • node version: 11.9.0
  • npm version: 6.7.0

Relevant code or config:

-

What you did:

I installed the latest Version of react-hooks-testing-library and got after a typecheck the following error.

What happened:

node_modules/@testing-library/react-hooks/node_modules/@types/react/index.d.ts:2817:14 - error TS2300: Duplicate identifier 'LibraryManagedAttributes'.

2817         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
                  ~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@types/react/index.d.ts:2816:14
    2816         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
                      ~~~~~~~~~~~~~~~~~~~~~~~~
    'LibraryManagedAttributes' was also declared here.

node_modules/@testing-library/react-hooks/node_modules/@types/react/index.d.ts:2881:13 - error TS2717: Subsequent property declarations must have the same type.  Property 'iframe' must be of type 'DetailedHTMLProps<IframeHTMLAttributes<HTMLIFrameElement>, HTMLIFrameElement>', but here has type 'DetailedHTMLProps<IframeHTMLAttributes<HTMLIFrameElement>, HTMLIFrameElement>'.

2881             iframe: React.DetailedHTMLProps<React.IframeHTMLAttributes<HTMLIFrameElement>, HTMLIFrameElement>;
                 ~~~~~~

node_modules/@types/react/index.d.ts:2816:14 - error TS2300: Duplicate identifier 'LibraryManagedAttributes'.

2816         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
                  ~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@testing-library/react-hooks/node_modules/@types/react/index.d.ts:2817:14
    2817         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
                      ~~~~~~~~~~~~~~~~~~~~~~~~
    'LibraryManagedAttributes' was also declared here.

Reproduction:

Problem description:

The issue is that I use the @types/react: 16.8.17 while this library uses @types/react: 16.8.22 which results in 2 different installed @types/react versions. After updating to the latest @types/react the problem was solved.

Suggested solution:

There should be any typescript dependency installen when I install this package.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 8
  • Comments: 25 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I think the problem should be solve by moving the @types definitions from the dependencies to the devDependencies in the package.json.

See also: https://docs.npmjs.com/files/package.json#devdependencies

For anyone following this issue, I’m thinking we’re going to follow the path of some other testing-library packages and move the types to DefinitelyTyped and make them a dependency here.

To be honest, I don’t know how it is any different from what we’re currently doing (other than moving the dependencies in a layer) or that it will make this situation any better, but I’m not seeing any complaints on the approach in the other package repos.

Happy for anyone to take the reigns on either the DefinatelyTyped side or the relevant changes here.

@mpeyper same issue.

Using: @testing-library/react-hooks@2.0.1

npm ls @types/react

react-accessible-shuttle@0.3.1
├─┬ @testing-library/react-hooks@2.0.1
│ ├── @types/react@16.9.1 
│ └─┬ @types/react-test-renderer@16.9.0
│   └── @types/react@16.9.2  deduped
├── @types/react@16.9.2 
└─┬ @types/react-dom@16.9.0
  └── @types/react@16.9.2  deduped

Maybe add it as an optional dependency?