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.
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.
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.
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.
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.
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.
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.
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.
#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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With