Suggestion: Ability to export just one class in a file like module.exports = Class;

Topics: Language Specification
Nov 19, 2012 at 8:17 PM
Edited Nov 20, 2012 at 11:10 AM

In node.js... There is a possibility to export just one object.

So instead of writing

exports.Request = {}...

you can write just

module.exports = Request;

and then use it like this:

var Request = require('./http/Request')

in TypeScript it seems this is not possible. You can do just something like this.

//http/Request.ts
export class Request {...}

//http/Response.ts
export class Response {...}

//app.ts
import http1 = module('./http/Request');
import http2 = module('./http/Response');

var request = new http1.Request;
var response = new http2.Response;

or use 

/// <reference path="./http/Request.ts" />

or pass it like arguments via command line

But then you have to compile everything into one file which is not always a good way (sometimes it's).

It would be very nice to somehow do something like this (which is possible in node.js via require).

import Request = module('./http/Request');
import Response = module('./http/Response');

Or am i just missing something? And if it's possible now, please, tell me how :)

Coordinator
Nov 20, 2012 at 4:23 PM

There's a feature request in the issue tracker tracking this, I believe:  http://typescript.codeplex.com/workitem/47

Nov 20, 2012 at 10:47 PM

Cool. Thanks for the link.