Code Monkey home page Code Monkey logo

Comments (6)

gilles-yvetot avatar gilles-yvetot commented on May 18, 2024

I just noted that you listed typescript as part of the deps

from cjstoesm.

wessberg avatar wessberg commented on May 18, 2024

Yes, typescript is a peer dependency and usage is documented here

from cjstoesm.

KaKi87 avatar KaKi87 commented on May 18, 2024

Hello,

required dependencies should be listed as dependencies and not as peerDependencies (source).

Please fix it accordingly.

Thanks

from cjstoesm.

wessberg avatar wessberg commented on May 18, 2024

@KaKi87,
Hi there.

I'm afraid you're misunderstanding or misinterpreting peer dependencies, how and when they're used, and why, including from the source you linked to.

The reason why libraries may declare a non-optional dependency as a peer dependency and not as a hard dependency is to allow consumers to use whatever version of the related package they want.

For optional peer dependencies, you can use peerDependenciesMeta and declare them as optional.

For example, if a library such as cjstoesm depended on something like typescript: ^4.6.3, that would force consumers of the library to depend on at least v.4.6.3 of TypeScript, even though they may be using another TypeScript version internally. Instead, cjstoesm supports any TypeScript version from v3.2 and up, and that makes it possible for you to use whatever TypeScript version you're targeting internally without being forced to update to the latest build.

from cjstoesm.

KaKi87 avatar KaKi87 commented on May 18, 2024

The reason why libraries may declare a non-optional dependency as a peer dependency and not as a hard dependency is to allow consumers to use whatever version of the related package they want.

Actually, the fact that your project would depend on a specific version of a package doesn't prevent the user from adding a different version of that package as a direct dependency.

EDIT: you could also use * if you wanted to make sure of it.

from cjstoesm.

wessberg avatar wessberg commented on May 18, 2024

Hi again.

Again, I want to reiterate that peer dependencies are not optional dependencies, as your comment seems to imply. You can, however, annotate them as such with peerDependenciesMeta as a library author if your package declares dependencies that the consuming user may only optionally install. TypeScript, however, is a required peer dependency of cjstoesm.

Please consult the official documentation or any of the existing great articles you can find online explaining when you may want to use peer dependencies, and when not to.

from cjstoesm.

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.