does somebody know how to do a module.exports?
I tried some different ways ending up with
export class Greeter {}
which will compile to
exports.Greeter = Greeter;
But what I really want is this:
exports = Greeter;
So that I can use it like this:
import Greeter = module("Greeter");
var greeter = new Greeter();
and not
import Greeter = module("Greeter");
var greeter = new Greeter.Greeter();
Is this possible with Typescript?
You can export a single class in TypeScript like this:
And here is how it's going to be used:
To be complete, here is my tsconfig.json (I am using TypeScript v2.0.3):
Currently no. This is a limitation in TypeScript and a limitation in the current straw-man module specification being considered by ECMA which TypeScript is patterned after.
This would be a great suggestion to make on CodePlex.
try this boilerplate app template https://github.com/ntheile/TypeScript-Backbone-Require-Boilerplate
This has now been implemented and is ready in TypeScript 0.9 :)
It's ugly and hacky, but you can still do:
Which compiles into:
So I think I've found a workaround. Just wrap the keyword 'module' in parentheses in your .ts file:
The generated javascript file will be exactly the same:
Note, better than declaring var module yourself, download the node.d.ts definition file and stick it in the same directory as your typescript file. Here is a complete sample of an express node.js routing file which assumes node.d.ts is in same directory:
I can then new up a SheetController and (using express) assign the view method:
I suppose any keyword can be escaped using this pattern: