title: How to get interface type of class properties for a factory method
body: <p>I have a factory method in some of my code where I want to pass in not only a Class type to instantiate, but a set of default values for the properties in the class.  I would like to get the typing such that the compiler will tell me if I try to pass in properties that do not exist in the class type being instantiated.  I can't figure out how to do this though.</p>
  
  <p>Here is a simple example showing what I would like to do.</p>
  
  <p>When I try it, I get a compiler error of: "An interface may only extend a class or another interface." for the interface <code>ClassProps</code> because it can't extend from <code>T</code>.</p>
  
  <pre><code>class Base {
     myId: number;
  }
  
  class Klass1 extends Base {
     myString: string;
     myNumber: number;
  }
  
  interface IBaseCtr&lt;T&gt; {
     new (): T;
  }
  
  // Get an interface that is the properties of the class passed
  interface ClassProps&lt;T extends Base&gt; extends T {}
  
  // This method compiles, but doesn't check the prop names
  //function factory&lt;T extends Base&gt;(ctrFunc: IBaseCtr&lt;T&gt;,
  //                                 initialData?: Object): T
  
  function factory&lt;T extends Base&gt;(ctrFunc: IBaseCtr&lt;T&gt;,
                                   initialData?: ClassProps&lt;T&gt;): T
  {
     let new_obj = new ctrFunc();
     Object.assign(new_obj, initialData);
     return new_obj;
  }
  
  
  let v1 = factory(Klass1, {myId: 10, myString: 'foo'});
  
  let v2 = factory(Klass1, {badVar: 10});
  </code></pre>
  
  <p>Any ideas how to get <code>initialData</code> typed so it will flag <code>badVar</code> as not being allowed in this second call?</p>