夫婦在如何獲得自定義類型在anuglar2 quickstart項目中工作的事情。第三方應用程序級別臨時類型
我以outlayer
庫https://github.com/metafizzy/outlayer爲例。
我已配置systemjs
加載依賴關係。它可以和能與import * as outlayer from "outlayer";
但我仍然得到編譯錯誤Cannot find module 'outlayer'.
爲了解決這個問題增加了一個分型文件outlayer.d.ts
直接向node_modules/outlayer
目錄,並更新了package.json
包括"typings": "./outlayer.d.ts",
。
//outlayer.d.ts
declare module Outlayer {
function create(str:string):any;
}
export = Outlayer;
將此文件直接添加到node_module並不理想,原因很明顯。無需分叉圖書館,處理這個問題的更好方法是什麼?更好的是,我怎樣才能在應用程序級別獲得簡單/快速的打字,這樣我就不用擔心馬上寫出整件事情了?例如,如果我試圖現在使用data
函數,我會看到Property 'data' does not exist on type 'typeof Outlayer'
總之,只需要能夠編寫一個自定義應用程序級別的類型,它不具有所有的好處,但也不會全部退出錯誤。一種臨時打字方式。
謝謝!
的偉大工程,只是需要用--global選項來安裝。 – Mike
已更新的答案。 – unional