接口上的Typescript typeof? [英] Typescript typeof on an interface?
问题描述
我最近在打字稿中发现了typeof关键字,几乎可以节省一天的时间。我想将dojo ContentPane描述为接口:
I've recently discovered the typeof keyword in typescript and it almost saves the day. I want to describe a dojo ContentPane as an interface:
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;
}
但是很遗憾,我无法在接口上执行typeof。我必须改为将ContentPane描述为一个类,但由于打字稿无法实现多重继承(通过扩展),我必须这样做吗?
But unfortunately I cannot do a typeof on an interface. I must instead describe ContentPane as a class but since typescript doesn't implement multiple inheritence (via extends) I must do this?
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的签名。 _容器?是否有关于为什么typeof SomeInterface无法正常工作的解释?
Is there an alternative which does not require me to duplicate the signature of dijit._Container? Is there an explanation as to why typeof SomeInterface does not work?
推荐答案
尚无法做到这一点(0.9.5 )。请参见工作项。
It is not yet possible to do this (0.9.5). See workitem.
这篇关于接口上的Typescript typeof?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!