TypeScript class per file in same namespace in Node.js
node.js, typescript
Solution
This will work if all the TypeScript files are compiled to a single JavaScript file using the `--out` option. No further code is required. Without this option, main.js (from main.ts) will not see module `foo` and a `ReferenceError` will be thrown.
Thanks to Basarat for linking to one of his videos which recommends the `--out` option: http://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1
Problem
What is the pattern for one class per file where multiple classes (and therefore multiple files) contribute to the same namespace? I'm asking this specifically in a Node.js context. I know how to define one class per file in the same namespace: foo/A.ts: ``` module foo { export class A { } } ``` foo/B.ts: ``` module foo { export class B { } } ``` main.ts: ``` /// <reference path="./foo/A.ts"/> /// <reference path="./foo/B.ts"/> // TODO: How do I import the foo namespace at runtime? ``` TypeScript is supposedly a language for application-scale JavaScript development, yet we seem to be left out in the cold on the most fundamental aspect of application-scale development, which is how to layout and structure code files and how everything is linked together at runtime.