Exporting constructos

Topics: General, Language Specification
Oct 16, 2013 at 9:25 AM
Edited Oct 16, 2013 at 9:25 AM
Is it possible to export constructors? Typically I have one class per module, so find it cumbersome to do this:
import myMod = require('myMod');
var a = new myMod.MyClass();
I'd rather do:
import MyClass= require('MyClass');
var a = new MyClass();
Is this what export default in harmony is for? When is this going to be supported?

Cheers,
Jon
Developer
Oct 16, 2013 at 1:51 PM
Yes, you can do that with an export assignment:
export = MyClass;
class MyClass {
   ...
}
If the above is in file "MyClass.ts" you can then import and use it with:
import MyClass = require("MyClass");
var a = new MyClass();
Oct 17, 2013 at 8:19 AM
Is it possible to simplify it?
export = class {
  ...
}
Thanks in advance.
Coordinator
Oct 17, 2013 at 5:37 PM
Not with the current design, which requires you to provide a symbol name on the right hand side of the 'export ='.

Using the symbol name is more flexible, as it lets you 'export =' a symbol that is a merged declaration, though I agree that a shorthand could also be convenient in other cases.