Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving npm @types typings with --save or --save-dev

TypeScript 2 recommends using npm for types. In The Future of Declaration Files.

the example is:

npm install --save @types/lodash 

My question is whether --save-dev should be used in an application, because TypeScript is transpiled and not deployed? Some comments on the article mention similar, but there is no answer I could see.

Perhaps --save is useful in a library to drag around the types when others install your library?

Am I missing something else this is useful for and what is the best practice? Thanks.

like image 808
RationalDev likes GoFundMonica Avatar asked Oct 18 '16 00:10

RationalDev likes GoFundMonica


People also ask

What is the difference between -- save and -- save Dev?

What does --save and --save-dev do? Well, You already know the answer now, don't you? --save saves the name and version of the package being installed in the dependency object. --save-dev saves the name and version of the package being installed in the dev-dependency object.

Should types be save Dev?

Using --save-dev is fine when you're writing a simple application, and it won't be used as a library. The problem comes along when you might have dependencies. If you stored your type declarations in your devDependencies, your consumers would not automatically get your type declarations.

What is -- save dev option in npm?

The --save option will save the package as well as the version to your packages. json file. The --save-dev option will save the package under devDependencies which is useful when installing only development packages that you may not want to ship in production.

What does @types mean in npm?

The @types npm organization is for obtaining type definitions with npm . Using these type definitions is a feature is coming in TypeScript 2.0. This will replace the current projects/tools such as typings and tsd, though these will continue to be supported for some time.

What is the --save-Dev option in NPM install?

The npm install command is used to install Node packages for your project under the node_modules/ folder. Most of the time, you have some packages that are needed only for development and testing purposes. The --save-dev option allows you to save packages under the devDependencies object in your package.json file.

How can I control where my npm packages get saved?

Additionally, you can control where and how they get saved with some additional flags: npm install <package_name> --no-save Prevents saving to dependencies. npm install <package_name> ---save-dev updates the devDependencies in your package. These are only used for local testing and development.

What should be the version of definitely typed on npm?

Should be higher than any currently published version, and should be a version of <libraryName> on npm. <libraryName>: Name of npm package that replaces the Definitely Typed types. Usually this is identical to <typingsPackageName>, in which case you can omit it.

What is the difference between dependencies and devdependencies in NPM?

#1. "dependencies": these packages are required by your application in production. #2. "devDependencies": these packages are only needed for development and testing This is the clearest simplest explanation in English. Documentation from npm for npm install <package-name> --save and npm install <package-name> --save-dev can be found here:


1 Answers

From Microsoft/types-publisher #81:

Using --save-dev is fine when you're writing a simple application, and it won't be used as a library. The problem comes along when you might have dependencies. If you stored your type declarations in your devDependencies, your consumers would not automatically get your type declarations. They'd then have to manually add your declaration file dependencies as their devDependencies.

Given that breaking consumers is a worse problem than slightly-larger packages, we've made --save the default in our documentation.

like image 61
Derek Avatar answered Oct 01 '22 22:10

Derek