title: TypeScript error TS2449: Class 'x' used before its declaration
body: <p>I don't understand the <code>tsc</code> compilation process with respect to<code>&lt;reference&gt;</code> and splitting the classes of a namespace across multiple files. I'm using the pattern:</p>
  
  <p><strong><code>src/base.ts</code></strong></p>
  
  <pre><code>namespace MyNameSpace {
    export class Base {
       /** constructor, etc. */
    }
  }
  </code></pre>
  
  <p><strong><code>src/subclass.ts</code></strong></p>
  
  <pre><code>/// &lt;reference path="./base.ts" /&gt;
  
  namespace MyNameSpace {
    export class Subclass {
       /** constructor, etc. */
    }
  }
  </code></pre>
  
  <p>This trivial example works. But as I use the pattern on more files, I periodically get the error <code>TypeScript error TS2449: Class 'x' used before its declaration.</code>.</p>
  
  <p>Are we back to manually managing declaration orderings, like <code>.c</code>/<code>.h</code> files? If so, what tools will help be back track the reference to find the error?</p>
  
  <p>My aim to have a manageable set of files that compile into a single <code>.js</code> and <code>.d.ts</code> (for another TypeScript library to use). If there a better solution for this scenario? Attempts with variations of Webpack and <code>import</code>s have failed me.</p>
  
  <p>If it matters, I'm also using nested namespaces, where the members are defined in subdirectories. I'm always using relative <code>reference</code> paths.</p>
  
  <p>This is very similar to <a href="https://stackoverflow.com/questions/13020651">typescript Base type &#39;xxxx&#39; is referenced before its declaration</a>, which dealt with a module split across multiple files.</p>