title: Cast JSON object to TypeScript class instance
body: <p>I have a class which have a method:</p>
  
  <pre><code> export class ItemType {
          id1: string;
          description: string;
  
          treeItemTypeDescription(): string {
              return this.id1 +  this.description;
          }
   }
  </code></pre>
  
  <p>I get the data of this class form web service and want to call this method:</p>
  
  <pre><code>itemTypeResource.parents(this.originalPosition).then((parents: app.domain.ItemType[]) =&gt; {
        console.log(typeof(parents[0]));
        console.log(parents[0].treeItemTypeDescription());
  });
  </code></pre>
  
  <p>But get the error:</p>
  
  <pre><code>TypeError: parents[0].treeItemTypeDescription is not a function
  </code></pre>
  
  <p>I think the reason of error the JS-object is not linked with TS-object. But I don't know how to fix it.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>console.log(Object.getOwnPropertyNames(parents[0]));</p>
  
  <p>gives only fields, but not methods:</p>
  
  <pre><code> ["autoincrementedId", "description", "entityType", "excelId", "excelParentId", "id1", "id2", "id3", "id4", "id5", "parentAutoId"]
  </code></pre>
  
  <p><strong>Update2:</strong></p>
  
  <p>If I create the object by myself all works fine:</p>
  
  <pre><code>  var s = new app.domain.ItemType();
    s.id1 = "1";
    s.description = "some";
    console.log(s.treeItemTypeDescription());
  </code></pre>