Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type conflicts in testing-library vs react #1184

Closed
ErinGreenhalgh opened this issue Feb 28, 2023 · 5 comments · Fixed by #1305
Closed

Type conflicts in testing-library vs react #1184

ErinGreenhalgh opened this issue Feb 28, 2023 · 5 comments · Fixed by #1305
Assignees
Labels
BREAKING CHANGE This change will require a major version bump bug Something isn't working

Comments

@ErinGreenhalgh
Copy link

  • @testing-library/react version: 12.1.2
  • Testing Framework and version: Jest 27.4.5
  • DOM Environment:
    jsdom: 16.6.0
    react: 17.0.2

What you did:

My team is not yet ready to upgrade to react 18, but I'd like to keep @testing-library/react as up to date as possible, so I'm trying to upgrade from 12.1.2 to 12.1.5.

What happened:

yarn upgrade @testing-library/react
yarn build

Found 177 errors in 2 files.

Errors  Files
   176  node_modules/@testing-library/react/node_modules/@types/react/index.d.ts:3085
     1  node_modules/@types/react/index.d.ts:3100

All the errors are related to type conflicts in react vs testing-library. Almost all of them are error TS2717:

node_modules/@testing-library/react/node_modules/@types/react/index.d.ts:3273:13 - error TS2717: Subsequent property declarations must have the same type.  Property 'view' must be of type 'SVGProps<SVGViewElement>', but here has type 'SVGProps<SVGViewElement>'.

3273             view: React.SVGProps<SVGViewElement>;
                 ~~~~

  node_modules/@types/react/index.d.ts:3288:13
    3288             view: React.SVGProps<SVGViewElement>;
                     ~~~~
    'view' was also declared here.

There is also one duplicate identifier error:

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

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

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

Problem description:

I expect to be able to upgrade testing-library without type conflicts.

Suggested solution:

I am not sure if this issue is a bug within testing-library, or some kind of dependency collision within my setup. I have tried upgrading @types/react but this results in even more errors.

@eps1lon eps1lon self-assigned this Feb 28, 2023
@eps1lon eps1lon added the bug Something isn't working label Feb 28, 2023
@eps1lon
Copy link
Member

eps1lon commented Feb 28, 2023

We need to move @types/react-dom to (optional) peer dependencies. Though this is technically a breaking change even though it rarely is practically. I'll read up again on prior discussions.

In the meantime, make sure you only have a single version of @types/react and @types/react-dom installed. facebook/react#24304 includes a couple of workarounds.

@ErinGreenhalgh
Copy link
Author

@eps1lon will do, thank you!

@eps1lon eps1lon added the BREAKING CHANGE This change will require a major version bump label Mar 8, 2023
@nickserv
Copy link
Member

nickserv commented May 28, 2023

I'm in favor of using optional peer dependencies too, as I've had module not found errors using Testing Library packages with strict package managers (pnpm, npm without the default install-strategy, and Yarn with nodeLinker: "pnp").

@nickserv
Copy link
Member

nickserv commented May 28, 2023

Actually this might be a duplicate of #1103. @eps1lon what do you think?

@eps1lon
Copy link
Member

eps1lon commented May 28, 2023

It's about different dependencies so I wouldn't consider this a duplicate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE This change will require a major version bump bug Something isn't working
Projects
None yet
3 participants