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.

Upvotes: 47

Views: 11185

Answers (1)

Derek
Derek

Reputation: 695

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.

Upvotes: 48

Related Questions