我最近在 typescript 中发现了 typeof 关键字,它几乎挽救了这一天。我想将一个 dojo ContentPane 描述为一个界面:
declare module dijit {
module layout {
interface ContentPane extends dijit._Widget, dijit._Container {
}
}
}
declare module "dijit/layout/ContentPane"
{
var ContentPane: typeof dijit.layout.ContentPane;
export = ContentPane;
}
但不幸的是我不能在接口(interface)上做 typeof。我必须改为将 ContentPane 描述为一个类,但由于 typescript 没有实现多重继承(通过扩展),我必须这样做吗?
declare module dijit {
module layout
{
class ContentPane extends dijit._Widget
implements dijit._Container
{
// how to avoid duplicating the _Container here?
addChild(widget: _WidgetBase, insertIndex?: number): void;
getIndexOfChild(child: _WidgetBase): number;
hasChildren(): boolean;
removeChild(widget: _WidgetBase): void;
removeChild(widget: number): void;
}
}
}
declare module "dijit/layout/ContentPane"
{
var ContentPane: typeof dijit.layout.ContentPane;
export = ContentPane;
}
有没有不需要我复制 dijit._Container 签名的替代方案?是否有关于为什么 typeof SomeInterface 不起作用的解释?
最佳答案
尚无法做到这一点 (0.9.5)。参见 workitem .
关于dojo - 接口(interface)上的 typescript 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21031912/