File namespaces vs module namespaces

Topics: Language Specification
Jun 16, 2013 at 10:14 AM
I've started to explore TypeScript, using v0.9, and I'm having some problems working out how file and module namespaces are supposed to be used. Suppose I'm writing some code for task A. So I start with a file A.ts and inside it I write something like
export module A {
  export function doA() {...}
And then in another file that wants to use A I'd write
var A = require('A');
But then I have to write A.A.doA(...) to access the function. So what's the recommended strategy here? Should I just remove the top-level module A, just defining the exported function at the top-level in the file, so I can write A.doA(...) in the calling context? That could work if I was defining just one "module" in each file I suppose. Or am I supposed to define an alias to the module in the calling context, assigning the result of the require to a temp, and then giving a local name to the module A? Or ...?

I suppose I'm not really sure why the result of the require has to be given a name at all; I'd really like the require to just import all the modules in that file into my local namespace. But maybe that's not possible given the constraints of needing an easy mapping to JavaScript.