module-internal declarations dont work across multiple files?

Topics: Language Specification
Oct 23, 2013 at 10:12 AM
Edited Oct 23, 2013 at 10:14 AM
While it is nice to spread a module on multiple files, it has a big disadvantage: I cannot use module-internal classes in another file inside the same module.

Workaround for me: I have to export the class, which breaks the whole idea of private declarations.

Or is there actual a way to acomplish this?

my sample:

file1.ts
module A{
   class SampleA { ... }
}
file2.ts
module A{

   class SampleB { 
       // this will not work, although it would, if the declarations would be in the same file
       var a = new SampleA();
      
      // wont work either, because SampleA is not exportet
      var a = new A.SampleA();
   }
}
Coordinator
Oct 30, 2013 at 12:24 AM
Edited Oct 30, 2013 at 12:25 AM
To make the symbols visible across merges, you need to export them from the module. For example:

file1.ts
module A {
   export class SampleA { }
}
file2.ts
module A {

    export class SampleB {
        constructor() {
            var a = new SampleA();
        }
    }
    export var a = new SampleA(); 
}