Git Product home page Git Product logo

Comments (25)

fxOne avatar fxOne commented on May 20, 2024 5

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

from react-hooks-testing-library.

mpeyper avatar mpeyper commented on May 20, 2024 2

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.

from react-hooks-testing-library.

atomicpages avatar atomicpages commented on May 20, 2024 1

@mpeyper same issue.

Using: @testing-library/[email protected]

npm ls @types/react

[email protected]
├─┬ @testing-library/[email protected]
│ ├── @types/[email protected] 
│ └─┬ @types/[email protected]
│   └── @types/[email protected]  deduped
├── @types/[email protected] 
└─┬ @types/[email protected]
  └── @types/[email protected]  deduped

Maybe add it as an optional dependency?

from react-hooks-testing-library.

mpeyper avatar mpeyper commented on May 20, 2024

We briefly had s release where we published a version that had a pinned version of the @types/react dependency, but we fixed that in 1.0.4 so I'm not sure why, assuming you also use a semver range, that you would end up with a duplicate.

None-the-less, as part of our package, we require the react type definitions, so we need to include it as a dependency. I'm not sure what the alternatives are that could avoid this circumstance from occurring? Happy to hear suggestions.

from react-hooks-testing-library.

mpeyper avatar mpeyper commented on May 20, 2024

If my type definitions have a dependency on another packages type definitions, then should they not be a dependency of my package?

Genuinely asking as I'm not a typescript use myself.

I can see that they could be considered a peer dependency, similar to react itself, but this is troublesome for non-typescript users as they will get a peer dependency if they don't install it, even though they don't need it. Perhaps this is a case for optional dependencies?

from react-hooks-testing-library.

fxOne avatar fxOne commented on May 20, 2024

I'm also new to TypeScript but when i look around I can only find projects which have their @types ind the devDependencies e.g.: https://github.com/jaredpalmer/formik/blob/4e629c9938ec628452af2ff2c2d537b795de1f56/package.json#L59

When I use TypeScript I already have the @types installed as I need them for development and when I don't use TypeScript I dont want to have the packges installed at all.

from react-hooks-testing-library.

mpeyper avatar mpeyper commented on May 20, 2024

Sorry for the delayed response.

You would only have the dependency installed if it was a library you were already using (which is likely in this case, but potentially not for all libraries out there). Assuming the depenency is a a compatible sevmer range, it the npm install should resolve to the same instance. If they are not compatibile, then you would have a problem anyway, even if it was a peerDependency.

Conversely, the cost of installing some type dependencies when you don't want them is pretty small.

from react-hooks-testing-library.

fxOne avatar fxOne commented on May 20, 2024

After doing some more research I found this ticket which says that it is the correct way to use dependency to add the @types: microsoft/types-publisher#81

At the end there are also some people which have compatibility issues when the @types are added to dependency so that they add them to devDependency.

Is it possible to change the "@types/react": "^16.8.22" dependency to "@types/react": ">=16.8.0" as this was the version when react hooks was introduced and we can use this great testing library?

from react-hooks-testing-library.

mpeyper avatar mpeyper commented on May 20, 2024

From my understanding of semver ranges, ">=16.8.0" would match any newer version, whereas "^16.8.0" would only match 16.x.x versions, which is probably safer to prevent breaking changes biting our users.

I use a bot for keeping dependency versions up to date, so I'm not sure if that will roll through a push it back up to latest again if we open up the range a bit more.

from react-hooks-testing-library.

fxOne avatar fxOne commented on May 20, 2024

As far as I can see you can configure your bot to exclude dependencies: enable
Also you more configuration options with the packageRules.

from react-hooks-testing-library.

tcoldmf avatar tcoldmf commented on May 20, 2024

I have the same problem.

from react-hooks-testing-library.

mpeyper avatar mpeyper commented on May 20, 2024

I have updated the version range in version 2 to be ">=16.9.0" with the intention if leaving at the minimum version for async act calls (which we now rely on so it can't be ">=16.8.0" like suggested above.

I'll close this now, but please let me know if this is still causing issues so we can try again at fixing it.

from react-hooks-testing-library.

filame avatar filame commented on May 20, 2024

I use version 2.0.1 and the issue still appears.

from react-hooks-testing-library.

mpeyper avatar mpeyper commented on May 20, 2024

Clearly there is more to be done here.

@atomicpages (or anyone), are you able to run npm dedupe and see if that helps?

from react-hooks-testing-library.

atomicpages avatar atomicpages commented on May 20, 2024

Running dedupe works (how I got around it in the first place 😉). But it is a pretty bad side effect, not 100% sure how this can be resolved permanently.

from react-hooks-testing-library.

mpeyper avatar mpeyper commented on May 20, 2024

For anyone following this, I've created the PR to add the type definitions to DefinitelyTyped -> DefinitelyTyped/DefinitelyTyped#38715

from react-hooks-testing-library.

mpeyper avatar mpeyper commented on May 20, 2024

The DefinitelyTyped changes went out in v2.0.2. Please update and let me know if there are still any issues.

from react-hooks-testing-library.

felixfbecker avatar felixfbecker commented on May 20, 2024

Could you document this as a breaking change in the 2.0.2 patch notes?

from react-hooks-testing-library.

mpeyper avatar mpeyper commented on May 20, 2024

Apologies about missing the release notes (I forgot to push the tags so didn't have that as a trigger to update them). I've updated them now.

I went with a non-breaking change version bump as the type definitions have not changed, just moved and it is hopefully resolving an issue some people are seeing on the current version. For anyone not having this issue, there should be no changes required.

from react-hooks-testing-library.

pvinis avatar pvinis commented on May 20, 2024

I see this closed with nothing changed?

@types/react are still in dependencies instead of devDependencies. This is still causing problems. I thought by now this is a known thing, that types go in the devdeps or peerdeps, never in the deps.

Any suggestions on how to use this library without getting silly errors like


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

3090             colgroup: React.DetailedHTMLProps<React.ColgroupHTMLAttributes<HTMLTableColElement>, HTMLTableColElement>;
                 ~~~~~~~~

  node_modules/@types/react/index.d.ts:2979:13
    2979             colgroup: React.DetailedHTMLProps<React.ColgroupHTMLAttributes<HTMLTableColElement>, HTMLTableColElement>;
                     ~~~~~~~~
    'colgroup' was also declared here.

?

from react-hooks-testing-library.

mpeyper avatar mpeyper commented on May 20, 2024

Hi @pvinis,

If you have any links to documentation or even articles on the best practice around this subject I'll happily read them and reconsider, however I did put quite a bit of effort into trying to understand the behaviour of this and replicating how type dependencies are when built by the DefinatelyTyped repo and am fairly comfortable with the approach we are currently taking.

I am aware of an issue with dependency resolution in yarn vs npm (#610) so perhaps that is what you are running into?

If you want to share more details about your setup (perhaps in a new issue) I'll happily dig in and see if there is a simple fix or workaround for you.

from react-hooks-testing-library.

pvinis avatar pvinis commented on May 20, 2024

I guess the one I can point to is microsoft/types-publisher#81 (comment). A lot of other discussions are basically this:

  • If people importing your lib cannot use it without another dep, only then put it in deps.
  • Otherwise, devdeps.

My question would be, do we need that in there?

I will try to do a RN init and and try to repro.

from react-hooks-testing-library.

pvinis avatar pvinis commented on May 20, 2024

Hm... in a new repo, I don't get the same problems, but I also see that it's using react 17. I will look into it, maybe our repo with 16 has some issues?

from react-hooks-testing-library.

pvinis avatar pvinis commented on May 20, 2024

Cleaning node_modules fixed it 🙈.

from react-hooks-testing-library.

nomasprime avatar nomasprime commented on May 20, 2024

Personally, I just avoid TS at every possible opportunity, the stuff of nightmares.

from react-hooks-testing-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.