title: Why does my TypeScript sometimes give me a instance and other times gives me a class?
body: <p>I'm writing an app to learn TypeScript. It works fine in Chrome, but I have a problem when running in Edge.  I've got this method:</p>
  
  <pre><code> set position(pos: Point) {
          const diffAsPoint = pos.minus(this.canvasPos);
  
          let diff: Vector2D = diffAsPoint.toVector2D(); // &lt;--- this line
          if (diff instanceof Vector2D) {
              console.info("is a vector!");
          } else {
              console.info("not a vector!");
          }
  </code></pre>
  
  <p>I'm seeing that, sometimes, diff IS a <code>Vector2D</code> as opposed to being an <em>instance of</em> a <code>Vector2D</code>.  Obviously, when this happens, any operation on it results in a <code>Object doesn't support property or method ...</code></p>
  
  <p><a href="https://i.stack.imgur.com/kZPQf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kZPQf.png" alt="debugger showing class rather than instance"></a></p>
  
  <p>The method <code>toVector2D</code> is simply:</p>
  
  <pre><code>toVector2D(): Vector2D {
      return new Vector2D(this.x, this.y);
  }
  </code></pre>
  
  <p>I don't know if this makes a difference, but here's some background:  </p>
  
  <ul>
  <li><p>the app is a game that runs in a game loop (60 frames a second - using <code>window.requestAnimationFrame(() =&gt; this.animloop());</code>)</p></li>
  <li><p>the app runs fine in Chrome</p></li>
  <li><p>it doesn't run fine in IE (it looks like a different issue, but I haven't been able to see what yet as IE and the Debugger Tools crash when investigating)</p></li>
  <li><p>it uses the latest TypeScript (2.2.1)</p></li>
  <li><p>it seems to happen at a random point after start-up, sometimes 2 seconds, sometimes 3 seconds</p></li>
  <li><p>there are other places in the code where this happens, all related to <code>Point</code> and <code>Vector2D</code>, seemingly related to creating them in every frame (some of the issues go away if I introduce a field rather than creating one every frame)</p></li>
  <li><p>I'm using AMD and requirejs</p></li>
  </ul>
  
  <p><strong>UPDATE -------</strong></p>
  
  <p>Using Edge and the debug tools and setting 'Always refresh from server', when loading from the web-site (<a href="http://pacmanweb.azurewebsites.net/" rel="nofollow noreferrer">http://pacmanweb.azurewebsites.net/</a>), I can see that the game <em>attempts</em> to run <strong>before all the modules are loaded</strong>.  Whereas in Chrome, it seems to wait for everything to load before running the game.</p>
  
  <p>Any ideas?</p>