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

Topics: Language Specification
Nov 19, 2012 at 7:17 PM
Edited Nov 20, 2012 at 10: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.

export class Request {...}

export class Response {...}

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 :)

Nov 20, 2012 at 3:23 PM

There's a feature request in the issue tracker tracking this, I believe:

Nov 20, 2012 at 9:47 PM

Cool. Thanks for the link.