背景
目前在我工作的地方,我们使用dojo.requires导入每个类所需的所有类。然而,在Dojo2.0中,他们正在摆脱dojo.require,转而使用amd require ( 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生成Dojo2.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....
}有没有办法实现我们想要做的事情?
谢谢
发布于 2012-11-26 00:22:30
在AMD模块中,一个模块等同于一个文件,所以如果你有一个文件名为:
dijit.forms.ts甚至是dijit.forms.d.ts
您可以使用以下命令加载它
import forms = module("dijit.forms");
var button = new forms.Button();在AMD应用程序的定义文件中,您不需要声明模块,因为该文件就是模块。
https://stackoverflow.com/questions/13536872
复制相似问题