title: TypeScript: Convert interface to class
body: <p>I have the following code:</p>
  
  <pre><code>interface X {
      type : string;
      val : number;
  }
  
  class X1 implements X {
      type : string;
      val : number;
  }
  
  var p1 : X[] = [{type:'a', val:8}];
  
  for (var n in p1) {
      var p2 : X1 = p1[n];
  }
  var p3 : X1 = p1[0];
  </code></pre>
  
  <p>Both p2 and p3 are declared as having type X1 and are initialized with a value of type X.</p>
  
  <p>The compiler happily accepts the declaration of p2, but it complains about p3 saying "Cannot convert 'X' to 'X1'".</p>
  
  <p>Why this difference?</p>