Export class as Node.js module in TypeScript

BraedenP picture BraedenP · Jul 6, 2013 · Viewed 13.5k times · Source

I'm familiar with the export keyword in TypeScript, and two canonical ways of exporting things from Node modules using TypeScript (of course, the TypeScript modules can be used as well, but they are even further from what I'm looking for):

export class ClassName { }

and a series of

export function functionName () { }

However, the way I usually write my modules, so that they are later imported as instantiable closures, is:

var ClassName = function () { };
ClassName.prototype.functionName = function () { };
module.exports = ClassName;

Is there a way I can do this using the TypeScript export syntax?

Answer

basarat picture basarat · Jul 6, 2013

You can do that quite simply in TypeScript 0.9.0 :

class ClassName { 
    functionName () { }
}

export = ClassName;