Search code examples
dojotypescripttypeof

Typescript typeof on an interface?


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;
}

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;
}

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?


Solution

  • It is not yet possible to do this (0.9.5). See workitem.