Chapter 6. Types Declarations and @types
Dependency management can be confusing in any language, and TypeScript is no exception. This chapter will help you build a mental model for how dependencies work in TypeScript and show you how to work through some of the issues that can come up with them. It will also help you craft your own type declaration files to publish and share with others. By writing great type declarations, you can help not just your own project but the entire TypeScript community.
Item 45: Put TypeScript and @types in devDependencies
The Node Package Manager, npm, is ubiquitous in the JavaScript world. It provides both a repository of JavaScript libraries (the npm registry) and a way to specify which versions of them you depend on (package.json).
npm draws a distinction between a few types of dependencies, each of which goes in a separate section of package.json:
dependencies
-
These are packages that are required to run your JavaScript. If you import
lodash
at runtime, then it should go independencies
. When you publish your code on npm and another user installs it, it will also install these dependencies. (These are known as transitive dependencies.) devDependencies
-
These packages are used to develop and test your code but are not required at runtime. Your test framework would be an example of a
devDependency
. Unlikedependencies
, these are not installed transitively with your packages. peerDependencies
-
These are packages that you require at runtime but ...
Get Effective TypeScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.