title: TypeScript: Defining constructor of parent class which is aware of child class's properties
body: <pre class="lang-js prettyprint-override"><code>abstract class Parent {
    public foo: string;
  
    constructor(v: Partial&lt;Parent&gt;) {
      Object.assign(this, v);
    }
  }
  
  class ChildA extends Parent {
    bar: string;
  }
  
  class ChildB extends Parent {
    baz: string
  }
  </code></pre>
  <p>In this setting,</p>
  <pre class="lang-js prettyprint-override"><code>const a = new ChildA({ foo: 'foo', bar: 'bar'});
  </code></pre>
  <p>gives the following error.</p>
  <pre><code>TS2345: Argument of type '{ foo: string; bar: string }' is not assignable to parameter of type 'Partial&lt;Parent&gt;'.
  Object literal may only specify known properties, and 'bar' does not exist in type 'Partial&lt;Parent&gt;'.
  </code></pre>
  <p><code>constructor&lt;T extends Parent&gt;(v: Partial&lt;T&gt;)</code> does not work neither. (TS1092: Type parameters cannot appear on a constructor declaration.)</p>
  <p>Can I define constructor of classes Parent, ChildA and ChildB in type safe way?</p>