2017-01-06 64 views
0

我也許做錯了什麼,但我找不到什麼幫助將不勝感激。我正在使用typescript 2 + jspm。我想我嘗試了使用typeRoots類型(在類型名稱中添加版本號)在tsconfig中的所有可能性。我現在的配置如下,它不工作,而我認爲這應該...與打字稿和jspm使用lodash

的package.json

"jspm": { 
    "dependencies": { 
     "lodash": "npm:[email protected]^4.17.4" 
    }, 
    "devDependencies": { 
     "@types/lodash": "npm:@types/[email protected]^4.14.45", 
     "babel": "npm:[email protected]^5.8.24", 
     "babel-runtime": "npm:[email protected]^5.8.24", 
     "core-js": "npm:[email protected]^1.1.4", 
     "systemjs": "npm:[email protected]^0.19.41" 
    } 
    } 

tsconfig.json

"typeRoots": [ 
    "jspm_packages/npm/@types" 
] 

然後編譯器不明白

import * as _ from "lodash" 

我得到

Cannot find module 'lodash'. 

由打字稿DOC https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html

現在,如果我刪除了進口的建議,有趣的是,VCODE能夠去找到,如果合併方法定義(F12)我寫下面的代碼行

_.merge(a, b); 

但是編譯器仍然抱怨

Identifier '_' must be imported from a module 

任何想法? :)

+0

您可以導入其他模塊沒有問題,或者它只是lodash哪些是有問題的? –

+0

我正在使用沒有pb的其他模塊 –

回答

0

這是不是一個真正的解決方案,但現在避免打字稿編譯器抱怨這是我做的

declare const _: any; 

我只是刪除了這一行,當我想爲方法簽名

注意的是完成當我進口lodash

System.import('lodash').then((lodash) => { 
    window._ = lodash; 
});