Home > OS >  What does yarn add --dev @types/package-name do?
What does yarn add --dev @types/package-name do?

Time:10-21

I'm not sure what --dev and @types/package-name does.

I tried to add react-color package to my react native project and encountered this error

Could not find a declaration file for module 'react-color'.

I resolved it by installing it using yarn add --dev @types/react-color

Would help if someone could breakdown what my error meant and how this solved the error. Thank you!

CodePudding user response:

This will add the package to the dev dependencies. This is the place where you put things that are not direct dependencies for your project (will not be included in the bundle) but are used in some other context. This is a good place to install typescript types declarations because they're only used in the build process.

CodePudding user response:

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript has its own syntax, function, and variables can have defined types, If you want to use library such as react-color you need to declare type definitions for TypeScript. Some libraries include typing file and you don’t need to install TypeScript’s type destination for them. But in case a library does not have .d.ts file, you need to install it.Type Search
Resources to explore:

  1. Type Declarations
  2. Ambient Declarations
  3. What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?
  • Related