npm @types 包的类型 globalDevDependencies 的等效性是什么?
What's the equivalence of typings globalDevDependencies for npm @types packages?
我想将 tsc@1.8 项目升级到 tsc@2,并在此过程中从我的工具链中删除 typings
。
这不是常见依赖项的问题,因为这些依赖项来自我的 typings.json
:
"dependencies": {
"bluebird": "registry:npm/bluebird#3.3.4+20160515010139",
"lodash": "registry:npm/lodash#4.0.0+20160416211519",
"mime": "registry:npm/mime#1.3.0+20160423043021"
}
我可以通过
轻松安装
npm i @types/bluebird @types/lodass @types/mime
但我的 typings.json
中也有一些 globalDevDependencies
用于我的测试设置:
"globalDevDependencies": {
"mocha": "registry:dt/mocha#2.2.5+20160317120654"
}
我的第一次尝试是:
npm install @types/mocha --save-dev
然而现在 tsc
抱怨它不知道 mocha
函数 it
和 describe
.
tests/unit/HelloServiceTest.ts(4,1): error TS2304: Cannot find name 'describe'.
tests/unit/HelloServiceTest.ts(5,5): error TS2304: Cannot find name 'it'.
tests/unit/HelloServiceTest.ts(10,5): error TS2304: Cannot find name 'it'.
总而言之,我错误地认为全局安装这些可能会解决问题:
npm i @types/mocha -g
我也偶然发现了 this issue,解决方案是不排除 tsconfig.json
中的类型文件夹:
"exclude": [
"node_modules",
"!node_modules/@types"
]
但它对我也不起作用,抛出同样的错误。
最后不知道如何实现typings
'globalDevDependencies
和globalDependencies
的效果,我只想用npm
和 @types/*
包而不是 typings
.
This thread 为我指明了正确的方向,因为我必须将类型添加到 tsconfig.json
:
{
"compilerOptions": {
"target": "ES6",
"types": ["node", "mocha", "chai"],
...
}
我想将 tsc@1.8 项目升级到 tsc@2,并在此过程中从我的工具链中删除 typings
。
这不是常见依赖项的问题,因为这些依赖项来自我的 typings.json
:
"dependencies": {
"bluebird": "registry:npm/bluebird#3.3.4+20160515010139",
"lodash": "registry:npm/lodash#4.0.0+20160416211519",
"mime": "registry:npm/mime#1.3.0+20160423043021"
}
我可以通过
轻松安装npm i @types/bluebird @types/lodass @types/mime
但我的 typings.json
中也有一些 globalDevDependencies
用于我的测试设置:
"globalDevDependencies": {
"mocha": "registry:dt/mocha#2.2.5+20160317120654"
}
我的第一次尝试是:
npm install @types/mocha --save-dev
然而现在 tsc
抱怨它不知道 mocha
函数 it
和 describe
.
tests/unit/HelloServiceTest.ts(4,1): error TS2304: Cannot find name 'describe'.
tests/unit/HelloServiceTest.ts(5,5): error TS2304: Cannot find name 'it'.
tests/unit/HelloServiceTest.ts(10,5): error TS2304: Cannot find name 'it'.
总而言之,我错误地认为全局安装这些可能会解决问题:
npm i @types/mocha -g
我也偶然发现了 this issue,解决方案是不排除 tsconfig.json
中的类型文件夹:
"exclude": [
"node_modules",
"!node_modules/@types"
]
但它对我也不起作用,抛出同样的错误。
最后不知道如何实现typings
'globalDevDependencies
和globalDependencies
的效果,我只想用npm
和 @types/*
包而不是 typings
.
This thread 为我指明了正确的方向,因为我必须将类型添加到 tsconfig.json
:
{
"compilerOptions": {
"target": "ES6",
"types": ["node", "mocha", "chai"],
...
}