Non-exported modules

Topics: Language Specification
Nov 15, 2013 at 2:23 PM
According to TypeScript spec, section 2.4:
"The scope of a non-exported entity declared within an internal module declaration is the body of that internal module declaration."

Seems logical for me that module is also "entity" here.
But TypeScript in playground gives me an error about duplicating identifiers for a code sample below. Please note that adding "export" before "module C" cures the error. Is this bug in the compiler or in the spec?
module A {
export module B {
  module C {
      export function a() {}    
  }
}
}

module A {
export module B {
module C {
export function a() {}
}
}
Developer
Nov 15, 2013 at 6:55 PM
This is working as intended but the spec wording there probably does need to be updated to be a bit more precise. In this case your two declarations for A.B.C are being merged per section 10.5 (Declaration Merging) of the spec. When you make one of the module C's exported they are no longer merged because they no longer have the same qualified name relative to a common root.
Nov 15, 2013 at 8:03 PM
Thanks for clearing that up! There is no mention in the spec about how qualified name is composed in relation to exported/not exported modules. Could we assume that qualified name is composed from the names of all internal parent modules from the root module downwards, but for non-exported modules something like "(not exported)" is added, so that function a in the example above would have full name like "A.B.C(not exported).a"?
Developer
Nov 15, 2013 at 9:28 PM
I believe the concepts you want to look for in the spec related to this are root module (specifically in 2.2 and 2.3) and common root. Specifically:

_The root module of an entity is defined as follows:
• The root module of a non-exported entity is the entity’s parent module.
• The root module of an exported entity is the root module of the entity’s parent module._

You're talking about moving 'down' from a root module to find a particular declaration that isn't actually visible which conceptually doesn't really make sense. As you can see there, the root module is defined in terms of moving 'up' from a particular declaration. What exactly would you be using this sort of description for?