Background
Currently at the place I work, we use dojo.requires to import all of our needed classes we use with each class. However, in Dojo 2.0 they are getting rid of dojo.require and going to the amd require style ( http://livedocs.dojotoolkit.org/releasenotes/migration-2.0 ):
require(["dijit/form/Button", "dojox/layout/ContentPane", ...],
function(Button, ContentPane, ...){
// CODE HERE
});
We currently have our dojo/dijit classes defined like the following in their own .d.ts files:
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;
}
}
This allows us to extend those classes like the following:
class CustomButton extends dijit.form.Button {}
Problem
We would like to be able to have typescript generate the Dojo 2.0 (amd) style requires, and do something like the following:
import Button = module("dijit/form/Button")
class CustomButton extends Button {}
Which we had hoped would compile to something like the following:
define(["require", "exports", "dijit/form/Button"], function(require, exports, Button)
{
///....Generated class
})
However, this does not work, as import only works for modules and not classes. We get an error like:
The name '"dijit/form/Button"' does not exist in the current scope
A module cannot be aliased to a non-module type
We’ve also tried to define the dijit classes like:
declare module "dijit/form" {
export class Button....
}
Is there a way we can achieve what we are trying to do?
Thanks
In AMD modules, a module equates to a file, so if you had a file named:
dijit.forms.ts or even dijit.forms.d.ts
You could load it using
Inside of the definition file for AMD applications you don’t need to declare the module, because the file is the module.