title: Why does typescript implicitly convert between unrelated classes?
body: <p>Typescript (1.4 &amp; whatever version is powering the typescriptlang.org playground) does not generate a compiler error on code that seems wrong with respect to implicit type conversion of classes that look "similar" in shape.  For instance:</p>
  
  <pre><code>class A {
      field: number;
  }
  
  class B {
      field: number;
  }
  
  function doSomething(a: A): void {
      if (!(a instanceof A))
          throw new Error("Not!")
  }
  
  doSomething(new B());
  </code></pre>
  
  <p>This compiles fine and then, of course, results in a runtime error although it seems typing should have prevented the compile.  Similarly I can convert from an interface to a class implicitly without error:</p>
  
  <pre><code>interface I {
      field: number;
  }
  
  class A implements I {
      field: number;
  }
  
  function doSomething(a: A): void {
      if (!(a instanceof A))
          throw new Error("Not!")
  }
  
  doSomething({ field: 3 });
  </code></pre>
  
  <p>Breaking the shape similarity by adding a method to the class not already found on the built-in Object in the above example results in the expected compile error instead of the implicit conversion.</p>
  
  <pre><code>interface I {
      field: number;
  }
  
  class A implements I {
      field: number;
  
      equals(i: I) {
          return this.field === i.field;
      }
  }
  
  function doSomething(a: A): void {
      if (!(a instanceof A))
          throw new Error("Not!")
  }
  
  doSomething({ field: 3 });
  </code></pre>
  
  <p>Is this how Typescript is supposed to behave?  Should we not be able to depend on <code>instanceof</code> returning an expected value in what seems to be type-safe code?</p>