Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I decide whether @types/* goes into `dependencies` or `devDependencies`?

I use TypeScript 2 in my project. I'd like to use some js library, but also typings for that library. I can install types with simple npm install @types/some-library. I'm not sure if I should --save or --save-dev them. It seems to me that even DefinetelyTyped GitHub readme kind of mentions both versions, but never explains them. I would think that @types should be in devDependencies, as types are needed for development and aren't used in runtime, but I saw many times @types in just dependencies. I'm confused.

How should I decide whether @types/* goes into dependencies or devDependencies? Are there actually some more or less official instructions?

like image 821
kamyl Avatar asked Jul 18 '17 20:07

kamyl


People also ask

How do you determine dependencies and devDependencies?

The rule of thumb is that if a module is imported by the application (e.g. with a require('foo') ), then it should be a dependency. Anything else goes as devDependency.

Should webpack be in dependencies or devDependencies?

Packages required to build the webpack project are under dependencies, rather than devDependencies . Node is historically used as a “server”, and still considered true.

What is difference between devDependencies and dependencies in flutter?

dev_dependencies are modules which are only required during development, while dependencies are modules which are also required at runtime.


1 Answers

Let's say you're developing a package "A" that have @types/some-module package in devDependencies. For some reason you're exporting the type from @types/some-module

import {SomeType} from 'some-module'; export default class APackageClass {      constructor(private config: SomeType) {       } } 

Right now Typescript consumers of package "A" are unable to guess what SomeType is, since devDependencies of package "A" are NOT installed.

In that particular case you NEED to place @types/* package with regular "dependencies". For other cases "devDependencies" are good enough.

like image 83
wookieb Avatar answered Sep 26 '22 00:09

wookieb