typescript – 将模块导入为类(dojo)

背景

目前在我工作的地方,我们使用dojo.requires导入我们在每个类中使用的所有需要​​的类.但是,在Dojo 2.0中,他们正在摆脱dojo.require并转到amd require style(http://livedocs.dojotoolkit.org/releasenotes/migration-2.0):

require(["dijit/form/Button","dojox/layout/ContentPane",...],function(Button,ContentPane,...){
    // CODE HERE
});

我们目前在他们自己的.d.ts文件中定义了如下所示的dojo / dijit类:

module dijit.form{
    export class Button extends dijit.form._FormWidget {
        showLabel : bool;
        _onClick (e:any) : any;
        _onButtonClick (e:any) : any;
        _setShowLabelAttr (val:any) : any;
        _clicked (e:any) : any;
        setLabel (content:String) : any;
        _setLabelAttr (content:String) : any;
        _setIconClassAttr (val:String) : any;
    }
}

这允许我们扩展这些类,如下所示:

class CustomButton extends dijit.form.Button {}

问题

我们希望能够让typescript生成Dojo 2.0(amd)样式需要,并执行以下操作:

import Button = module("dijit/form/Button")
class CustomButton extends Button {}

我们希望编译成以下内容:

define(["require","exports","dijit/form/Button"],function(require,exports,Button)    
{
    ///....Generated class    
})

但是,这不起作用,因为import仅适用于模块而不适用于类.我们收到如下错误:

The name '"dijit/form/Button"' does not exist in the current scope
A module cannot be aliased to a non-module type

我们还试图定义dijit类,如:

declare module "dijit/form" {
    export class Button....
}

有没有办法可以实现我们想做的事情?

谢谢

解决方法

在AMD模块中,模块等同于文件,因此如果您有一个名为的文件:

dijit.forms.ts甚至dijit.forms.d.ts

你可以使用它加载它

import forms = module("dijit.forms");

var button = new forms.Button();

在AMD应用程序的定义文件中,您不需要声明模块,因为该文件是模块.

相关文章

我最大的一个关于TypeScript的问题是,它将原型的所有方法(无...
我对React很新,我正在尝试理解子组件之间相互通信的简洁方法...
我有一个非常简单的表单,我将用户电子邮件存储在组件的状态,...
我发现接口非常有用,但由于内存问题我需要开始优化我的应用程...
我得到了一个json响应并将其存储在mongodb中,但是我不需要的...
我试图使用loadsh从以下数组中获取唯一类别,[{"listing...