title: Cross referencing with extended classes in TypeScript
body: <p>I've found a strange bug.</p>
  
  <p>If you have two classes in different files, and for example class <strong>B</strong> extends class <strong>A</strong>, and class <strong>A</strong> has a variable typed <strong>B</strong>, TypeScript compiles in wrong order with --out main.js command (when you compile whole project into one file).
  Wrond order results that javascript throws an error: <em>Uncaught TypeError: Cannot read property 'prototype' of undefined</em> 
  This is because class <strong>B</strong> is earlier in the code than <strong>A</strong>, and it want to use it.</p>
  
  <p>Here is the simpliest example:</p>
  
  <p><strong>A.ts</strong></p>
  
  <pre><code>///&lt;reference path='B.ts'/&gt;
  
  class A
  {
      public b: B;
  
      constructor()
      {
      }
  
      init()
      {
          this.b=new B();
      }
  }
  </code></pre>
  
  <p><strong>B.ts</strong></p>
  
  <pre><code>///&lt;reference path='A.ts'/&gt;
  class B extends A
  {
      constructor()
      {
          super();
      }
  }
  </code></pre>
  
  <p><strong>app.ts</strong></p>
  
  <pre><code>///&lt;reference path='A.ts'/&gt;
  var a: A=new A();
  a.init();
  </code></pre>
  
  <p><strong>Generated main.js</strong></p>
  
  <pre><code>var __extends = this.__extends || function (d, b) {
      function __() { this.constructor = d; }
      __.prototype = b.prototype;
      d.prototype = new __();
  };
  var B = (function (_super) {
      __extends(B, _super);
      function B() {
          _super.call(this);
      }
      return B;
  })(A);
  var A = (function () {
      function A() {
      }
      A.prototype.init = function () {
          this.b = new B();
      };
      return A;
  })();
  var a = new A();
  a.init();
  //@ sourceMappingURL=main.js.map
  </code></pre>
  
  <p>Is there a workaround?</p>