2016-11-30 77 views
1

我想從我的工具鏈中將[email protected]項目升級到tsc @ 2並且在過程溝typings中。npm @types包的類型globalDevDependencies的等價性是什麼?

這不是一個問題,共同depencies因爲這些依賴從我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 

安裝但我也有一些globalDevDependencies在我的測試設置我typings.json

"globalDevDependencies": { 
    "mocha": "registry:dt/mocha#2.2.5+20160317120654" 
} 

我的第一次嘗試是:

npm install @types/mocha --save-dev 

然而現在tsc抱怨不知道mocha功能itdescribe

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'globalDevDependenciesglobalDependencies了,當我想用​​剛npm@types/*包代替typings

回答

1

This thread我指出了正確的方向,因爲我要的類型添加到tsconfig.json

{ 
    "compilerOptions": { 
    "target": "ES6", 
    "types": ["node", "mocha", "chai"], 
    ... 
} 

The types option also have a verbose documentation.

+0

謝謝!這對我有效。我對文檔的解釋是,這些類型應該默認包含,但是如果沒有這個,它有點令人困惑。 「默認情況下,所有可見的」@types「包都包含在您的編譯中。」 – pulekies

相關問題