Skip to content

@testing-library/react has transitive deps to @types/react: * #508

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

Closed
jackyef opened this issue Oct 25, 2019 · 6 comments
Closed

@testing-library/react has transitive deps to @types/react: * #508

jackyef opened this issue Oct 25, 2019 · 6 comments

Comments

@jackyef
Copy link

jackyef commented Oct 25, 2019

  • react-testing-library version: 9.3.0

What you did:

We have a react library written in typescript that has exact devDependency to @types/react: "16.9.9". @testing-library/react` is also one of the library devDependencies.

What happened:

When installing all devDependencies (including bundler and babel stuffs) so we can build our library, we ended up with 2 different @types/react, because @testing-library/react has deps to @types/react: *, which resolves to a newer version of @types/react.

Because there are 2 different @types/react, tsc will fail when trying to build our package.

Suggested solution:

Set @types/* packages as devDependencies of @testing-library/react

@kentcdodds
Copy link
Member

Hi @jackyef,

Thanks for the issue. React Testing Library does not include @types/react in the package.json at all. I don't think that this package is the culprit to your problems. Good luck!

@jackyef
Copy link
Author

jackyef commented Oct 29, 2019

@kentcdodds Hi, you're right, I was incorrect in saying it was one of @testing-library/react deps, it was actually one of the transitive dependencies!

It goes like this:

  1. @testing-library/react has deps to @types/testing-library__react
  2. @types/testing-library__react has deps to @types/react-dom,
  3. @types/react-dom has deps to @types/react
> yarn why @types/react
yarn why v1.16.0
[1/4] Why do we have the module "@types/react"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "@types/[email protected]"
info Reasons this module exists
   - "@testing-library#react#@types#testing-library__react#@types#react-dom" depends on it
   - Hoisted from "@testing-library#react#@types#testing-library__react#@types#react-dom#@types#react"
Done in 0.15s.

Would there be a problem if we make @types/testing-library__react as a devDependencies instead of dependencies of @testing-library/react?

@jackyef jackyef changed the title @testing-library/react has deps to @types/react: * @testing-library/react has transitive deps to @types/react: * Oct 29, 2019
@kentcdodds
Copy link
Member

Including them as dependencies is an intentional choice (read more: #437).

Is there a reason you're not using the latest version of the react types? I think you probably should...

@jackyef
Copy link
Author

jackyef commented Oct 30, 2019

Ah, I see! That was interesting to read the perspective of everyone involved :)

For my specific case, yes, it would be totally fine to just use the latest version of @types/react.

For what it's worth, some people might be using an older version of react and therefore use old version @types/react to match. The amount of that specific case is probably really small though.

I understand shipping @types/testing-library__react along with @testing-library/react is intentional, but what about having @types/react as deps of @types/testing-library__react? Could that be made a devDep? People should still get the typings for @testing-library/react automatically.

@eps1lon
Copy link
Member

eps1lon commented Oct 30, 2019

@jackyef That is a long standing issue with how types are published from DefinitelyTyped. TL;DR: @types/react: "*" is a hack for optional peer dependencies.

Most package managers do support these now so we can revisit this over at DefinitelyTyped. In the meantime I suggest you get familiar with manually editing your lockfile. For yarn.lock you can post every entry for @types/react here and I can patch it so that you have a single, older version of @types/react. For npm I can't help you unfortunately.

@jackyef
Copy link
Author

jackyef commented Nov 1, 2019

We have fixed this issue on our end. My reason for continuing the discussion here is mostly just to satisfy my curiosity 😃

I'll be looking forward to hear the updates over at DefinitelyTyped then, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants