我如何决定@types/* 是进入`dependencies` 还是`devDependencies`? [英] How do I decide whether @types/* goes into `dependencies` or `devDependencies`?
问题描述
我在我的项目中使用 TypeScript 2.我想使用一些 js 库,但也想使用该库的类型.我可以使用简单的 npm install @types/some-library
安装类型.我不确定我是否应该 --save
或 --save-dev
它们.在我看来,即使 DefintelyTyped GitHub 自述文件也提到了这两个版本,但从未解释过它们.我认为@types 应该在 devDependencies
中,因为类型是开发所需要的,而不是在运行时使用,但我在 dependencies
中看到很多次 @types.我很困惑.
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.
我应该如何决定@types/* 是进入dependencies
还是devDependencies
?是否有或多或少的官方说明?
How should I decide whether @types/* goes into dependencies
or devDependencies
? Are there actually some more or less official instructions?
推荐答案
假设您正在开发一个包A",它在 devDependencies 中有 @types/some-module 包.出于某种原因,您从 @types/some-module
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) {
}
}
现在包A"的 Typescript 消费者无法猜测 SomeType 是什么,因为包A"的 devDependencies 没有安装.
Right now Typescript consumers of package "A" are unable to guess what SomeType is, since devDependencies of package "A" are NOT installed.
在这种特殊情况下,您需要将@types/* 包与常规依赖项"放置在一起.对于其他情况,devDependencies"就足够了.
In that particular case you NEED to place @types/* package with regular "dependencies". For other cases "devDependencies" are good enough.
这篇关于我如何决定@types/* 是进入`dependencies` 还是`devDependencies`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!