【发布时间】:2017-04-14 14:37:27
【问题描述】:
我想将一个 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"
]
但它也对我不起作用,抛出同样的错误。
最后,当我只想使用npm和@types/*包而不是@987654343时,我不知道如何达到typings'globalDevDependencies和globalDependencies的相同效果@。
【问题讨论】:
标签: node.js typescript types npm typescript-typings