2017-10-21 142 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