-
Notifications
You must be signed in to change notification settings - Fork 148
Allow type to have peerDependencies instead of dependencies. #431
Comments
Absolutely agree. This makes it a pain for example to use react components with preact when using typescript. |
It is also possible for these kinds of inherent dependencies to intersect in nasty ways with npm and yarn's resolution algorithms and preference (given a lockfile) not to update nested dependencies (cf. #360). In our own app, for example, we have a direct dependency on Yarn tries to preserve whatever it had previously installed there, so we end up with two separate copies of |
It's a bit of a pickle because we have no way to validate, on the DT side, that someone's PR doesn't break some combination of |
Totally makes sense. If a type explicitly sets a dependency in its own |
Can't this be automated like the dependencies are? I had a simple idea: If one of these extracted dep is peer in the original module, add them as peer instead of dependency :) |
@andy-ms opinions on the above? Seems reasonable but I haven't slept much 🙃 |
"peerDependencies" would mean that people would have to remember to install those, while "dependencies" are installed automatically. Not a big deal since npm gives a warning, but we might want to update typingsInstaller to look for peerDependencies and install those too. |
Most of the time, when somebody install something like @types/react-redux, @types/react is already installed. That's the point of peerDependencies :) If package developer choose to have a peerDependency instead of a dependency there must be a reason a typing package should respect that... But yeah, I agree that |
This issue is causing a lot of pain at the moment. All of my definitely typed libs are currently reporting "Conflicting definitions for 'node'" because the version of node has automatically incremented to Any idea or work arounds appreciated. Current 'work around' is to copy the declaration files into the project and reference them directly and remove the @types/* dependency from package.json UPDATE: this appears to have been primarily caused by an incorrectly configured typerRoots. |
My case is targeting webpack 3, hence including But as soon I install "@types/webpack-dev-server": "^2.9.4" with a generated package.json of
where |
Right now it looks a lot, from the user's perspective, like there are two bad choices: knowingly break some projects where the "dependencies" behavior causes issues, or un-knowingly break some other projects where the "peerDependencies" behavior causes issues. I feel like the latter is a much better situation for users of TS because there are avenues for fixing the issue: don't install the peerDependencies and ignore the incorrect PD warnings from yarn/npm or PR the So while you're correct that you can't 100% guarantee that packages' peerDependencies don't create an impossible dependency graph, you can 100% guarantee that the current behavior does cause impossible dependency graphs, and it seems like this is a case of perfect being the enemy of good and letting bad win. |
Yeah, it sure seems like any plugin is going to need to list the host's typings in |
Currently, when a type is published, all imported types are added as dependencies.
Example: react-router v3:
But as react is a peerDependency of react-router, you can easily have an application with react@15 and react-router.
In that case definitions are broken because npm install react@16 as child of react-router.
definitions dependencies should strictly follow what is defined is the module package.json. If a dependency is a dependency, type dependency should be a type dependency, in dependency is a peerDependency, type dependency should be a peerDependency.
The text was updated successfully, but these errors were encountered: