2017-10-21 291 views
0

我在查找如何爲下面的代碼編寫類型定義時遇到了一些問題。我想最好的方式來描述它是一個靜態類,其中包含一個命名的構造函數。靜態類上的構造函數的打字稿定義

var ajaxAdapter = new IAjaxAdapter.implement({ 
    ajax: function (work: IAjaxRequest) { 
     ... 
    } 
} 

但我得到一個生成錯誤Property 'implement' does not exist on type 'typeof IAjaxAdapter'

我d.ts看起來像現在這個權利,但很明顯這是一個有點不對勁

export class IAjaxAdapterInstance { 
    constructor(any: any); 
    ajax: (request: IAjaxRequest) => void; 
} 
export class IAjaxAdapter { 
    implement: IAjaxAdapterInstance; 
} 

我不知道這是可能的,如果不是我想我可以在任何類型的...但我希望得到一些東西。

回答

1

只看該類型的,因爲你使用implement爲是指一類,而不是對象的靜態屬性,如果添加一個static應該鍵入和typeof

export class IAjaxAdapter { 
    static implement: typeof IAjaxAdapterInstance; 
} 
+0

這工作一級棒!另外,我不知道你可以在定義文件中使用static和typeof,好好學習! – k2snowman69