This project is read-only.

Anonymous/Unnamed Modules

Topics: Language Specification
Dec 26, 2012 at 11:29 PM
Edited Dec 28, 2012 at 1:38 AM

Hi, thanks for the great work on TypeScript. I'm liking it more than any other languages that compile to JS.
I would like to suggest the following: Why not have anonymous/unnamed modules? The following code snippet totally makes sense for me to compile:

module {
  class Simple {
    constructor(public name: string) {}

    greet(who: string) {
      return "Greetings "+ who +", I'm "+ +"!";
    static main() {
      var s = new Simple('Flynn');

The generated code should be wrapped in a closure function and not cluttering the global scope.

(function () {

 // ...


Also it would be nice to have a compiler option to put everything compiled in an anonymous module so that the global namespace is not cluttered.

The above snippet is with little modification from:


Dec 28, 2012 at 7:33 PM

Anonymous modules are something we have been discussing for a while, and hope to do soon.  The pattern in the example you give is exactly the kind of idiomatic code we'd hope to provide 'syntactic sugar' for.

Thanks for trying TypeScript and for taking the time to give us feedback!

Apr 12, 2014 at 12:26 AM
Created issue item for this here.