title: Angular 2 map http response to instance of class
body: <p>I'm wondering what the best way is to map the http response from a get request to a class instead of a basic Javascript object.</p>
  
  <p>In my current attempt I simple do <code>new ClassName(data)</code>, but there might an obscure Angular specify and completely awesome way to do this that I don't know.</p>
  
  <p>Here's my current code:</p>
  
  <pre><code>getPost(id:number){
      return this._http.get(this._postsUrl+'/'+id)
                  .map(res =&gt; new Post(res.json().data))
                  .do(data =&gt; console.log(data))
                  .catch(this.handleError);
  }
  </code></pre>
  
  <p>I need Post to be a class and not just an interface because I have methods inside.</p>
  
  <p>I followed the HeroTutorial and the http "developer guide" along and in their <code>getHeroes</code> method they do:</p>
  
  <pre><code>getHeroes () {
  return this.http.get(this._heroesUrl)
                  .map(res =&gt; &lt;Hero[]&gt; res.json().data)
                  .catch(this.handleError);
  }
  </code></pre>
  
  <p>I somehow expected the <code>&lt;Hero[]&gt;</code> part to do just that: Take the Hero class and create new instances of it, but my tests show that it doesn't, this is pretty much just for Typescript to know what to expect.</p>
  
  <p>Any ideas ? Thanks!</p>