title: How to add a property to an existing object to satisfy an interface in typescript?
body: <p>Here's what I would like to do in a nutshell:</p>
  
  <pre><code>interface A {
       prop1: string;
  }
  
  interface B extends A {
      prop2: string;
  }
  
  someImportantFunction(x: A): B {
      var ret: B = x.prop2 = someCalculation(); //Error, but if possible x would now satisfy B
  
      return ret;
  }
  </code></pre>
  
  <p>The english version of my question is: how can I add new properties to an existing object in typescript, with the goal of satisfying a more-derived interface definition? Perhaps this is not possible, or I am missing some obvious approach.</p>
  
  <p>UPDATE:
  Also, suppose the list of properties on interface A is long, so boilerplate assignment by mapping properties is laborious and not clean.</p>
  
  <p>I also see something like this would work, but it seems like a hack:</p>
  
  <pre><code>someImportantFunction(x: A): B {
      var ret: B = &lt;B&gt;x;
      ret.prop2 = someCalculation();
  
      return ret;
  }
  </code></pre>
  
  <p>Thanks,
  Mathias</p>