title: Place Object received from server into my own class
body: <p>I have the following class setup. </p>
  
  <p><strong>Deviceinfo  class</strong></p>
  
  <pre><code>export class DeviceInfo {
  _id: string; // MongoDb automatically adds this so this is just a placeholder
  // tslint:disable-next-line: ban-types
  id: string;
  // tslint:disable-next-line: ban-types
  name: String;
  photo: string;
  // Class contains all information on specific devices such as their ID, CurrentOwner and their ImageUrl
  constructor(id2: string, devOwner: string, ph: string) {// Constructor to create an instance of the class
      this.id = id2;
      this.name = devOwner;
      this.photo = ph;
  
  }
  }
  </code></pre>
  
  <p>And i sent a request to a server to get info on devices stored in this info. 
  I use the following method to get values from the server </p>
  
  <p><strong>Code from deviceinfo.ts class</strong></p>
  
  <pre><code>   this.getdeviceinfo().then(res =&gt; {
  
  
      })
      .catch(err =&gt; {});
  </code></pre>
  
  <p>The method looks like this</p>
  
  <p><strong>GetDeviceinfo method</strong></p>
  
  <pre><code>   async getdeviceinfo() {
    return await new Promise( (resolve, reject) =&gt; {
      let timesDone = 0;
      // tslint:disable-next-line: no-var-keyword
      const viewDevicesLink = '/devices/info/view'; // parameter: email
      const xhr = new XMLHttpRequest();
      // xhr.open('POST', this.AUTH_SERVER_ADDRESS + '/user/devices/view/', true);
      xhr.open('POST', this.AUTH_SERVER_ADDRESS  + viewDevicesLink, true);
  
      xhr.setRequestHeader('Content-type', 'application/JSON;charset=UTF-8');
      const us = new DeviceInfo('1', '', '');
  
  
      xhr.send(JSON.stringify(us));
  
      xhr.addEventListener('readystatechange', processRequest, false);
  
      xhr.onreadystatechange = processRequest;
  
      function processRequest(e) {
          // tslint:disable-next-line: triple-equals
          if (xhr.readyState == 4 &amp;&amp; xhr.status == 200) {
              // tslint:disable-next-line: triple-equals
              if (timesDone == 0) {
                  // tslint:disable-next-line: prefer-const
                  const response  = xhr.response;
                  timesDone++;
                  alert(JSON.parse(response));
                  resolve(JSON.parse(response));
  
              }
          // tslint:disable-next-line: triple-equals
          } else if (xhr.readyState == 4) {
              alert('server error: ' + xhr.status + ', response is: ' + xhr.responseText);
              timesDone++;
              return null;
          }
  
      }
  
    });
  </code></pre>
  
  <p>} </p>
  
  <p>The method gets the information and when i stringify the response from the server i in the classinfo.ts class i get the following.  </p>
  
  <pre><code>{"_id":"5d7548aa1c9d4400009d0c66","id":"1","name":"Mr Meowgi's Old Person Collar","photo":"data:image/jpeg;base64,/9j and then some jiberish 
  </code></pre>
  
  <p>Which is great but how do i get this response(the object it returns) into a instance of the Deviceinfo class? 
  I used </p>
  
  <pre><code>var device = res. 
  </code></pre>
  
  <p>but that is the simply of type unknown. How would i get it to be of type deviceInfo? Thanks for the help</p>