我在這裏試圖擴展包裝類型的命名空間,@typings/fullcalendar
。從包裝類型擴展命名空間
/// <reference path="./types/fullcalendar" />
import * as fullcalendar from 'fullcalendar';
import { TimeGrid } from 'fullcalendar';
// TimeGrid and fullcalendar.views are used then
可以看到原件類型here。
而且fullcalendar-custom.d.ts是
import * as FC from 'fullcalendar';
export as namespace FC;
declare class TimeGrid { prepareHits() }
declare let views: any;
這導致類型錯誤,所以很明顯,fullcalendar
命名空間是不正確擴展:
TS2305:模塊「」 .../node_modules/@ types/fullcalendar/index「'沒有導出成員'TimeGrid'。
TS2339:類型'typeof「.../node_modules/@ types/ fullcalendar/index」'上不存在屬性'views'。
這應該怎麼做纔是正確的?
在這裏可以避免使用reference
指令,考慮到types
目錄在typeRoots
中指定?
該應用程序與Webpack和awesome-typescript-loader捆綁在一起,因此其行爲可能與其他編譯方法不同。在某些時候IDE的檢測類型(WebStorm)類型似乎沒有問題,但編譯時仍然出現類型錯誤。
謝謝,我儘量避免再次出口,因爲我沒有在延長打字的地方延長包裹,但它完成了工作。我結束了'聲明類免費...出口默認 origFC; '。 TS的名稱空間可以正常使用,但會導致IDE出現一些類型問題。 –
estus