title: Angular and TypeScript: instantiating an instance of a class from a JSON object
body: <p>I have an interface to represent the response from my Web API:</p>
  
  <pre><code>interface Person {
    dateofbirth: string;
    firstname: string;
    lastname: string;
  }
  </code></pre>
  
  <p>But I don't want to deal with a string representation of a date-time. Instead, I want to deal with a <code>MomentJS</code> object. So I create a class for a view model that has a <code>MomentJS</code> property. When constructing it, I convert the string to a <code>MomentJS</code> object:</p>
  
  <pre><code>class PersonViewModel {
        dateofbirth: Moment.moment;
        firstname: string;
        lastname: string;
  
        constructor(dateofbirth: string, firstname: string, lastname: string) {
          this.dateofbirth = moment.utc(dateofbirth);
          this.firstname = firstname;
          this.lastname = lastname;
        }
  }
  </code></pre>
  
  <p>But, if the response from the Web API contains more than 10 fields (which is usually the case), I find myself doing a lot of manual work. I tried third-party tools that make it easier to instantiate objects given a JSON object, but I don't want to rely on third-party tools for such a critical part of my application.</p>
  
  <p>My question is - is there any native TypeScript feature that could simplify this process? Or should I take an entirely different approach?</p>