问题描述
我在项目中使用TypeScript 2.我想使用一些js库,但也要使用该库的类型.我可以使用简单的npm install @types/some-library
安装类型.我不确定是否应该--save
或--save-dev
他们.在我看来,即使DefinetelyTyped 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"的devDependencies,软件包"A"的Typescript使用者无法猜测SomeType是什么.
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`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!