title: typescript - cloning object
body: <p>I have a super class that is the parent (<code>Entity</code>) for many subclass (<code>Customer</code>, <code>Product</code>, <code>ProductCategory</code>...)</p>
  
  <p>I'm looking to clone dynamically an object that contains different sub objects in Typescript. </p>
  
  <p>In example : a <code>Customer</code> that has different <code>Product</code> who has a <code>ProductCategory</code></p>
  
  <pre><code>var cust:Customer  = new Customer ();
  
  cust.name = "someName";
  cust.products.push(new Product(someId1));
  cust.products.push(new Product(someId2));
  </code></pre>
  
  <p>In order to clone the whole tree of object I created a function in <code>Entity</code> </p>
  
  <pre><code>public clone():any {
      var cloneObj = new this.constructor();
      for (var attribut in this) {
          if(typeof this[attribut] === "object"){
             cloneObj[attribut] = this.clone();
          } else {
             cloneObj[attribut] = this[attribut];
          }
      }
      return cloneObj;
  }
  </code></pre>
  
  <p>The <code>new</code> rises the following error when it is transpiled to javascript: <code>error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.</code></p>
  
  <p>Although the script works, <strong><em>I would like to get rid of the transpiled error</em></strong></p>