title: Angular map HttpClient.Post
body: <p>So I finally decided to catch up with the times and migrate some old angular <code>Http</code> stuff to <code>HttpClient</code>.</p>
  
  <p>The app used to run on a bunch of Promise based code, which has since been removed (mostly). <br>My old Promise function looked something like this:</p>
  
  <pre><code>public getUser(profileId: number): Promise&lt;User&gt; {
      return this.http.post("/api/url", postObject, HttpSettings.GetDefaultHttpRequestOptions());
      .map(u =&gt; new User(u))
      .catch(this.handleError)
      .toPromise();
  }
  </code></pre>
  
  <p>My new HttpClient function is much nicer:</p>
  
  <pre><code>public getUser(profileId: number): Observable&lt;any&gt; {
      return this.http.post("/api/url", postObject, HttpSettings.GetDefaultHttpRequestOptions());
  }
  </code></pre>
  
  <p>But what I don't like currently is that in <strong>each</strong> subscription to this, I now have to map the data to an instance of User...</p>
  
  <pre><code>service.getUser(1).subscribe(data =&gt; {
      data = new User(data);
  });
  </code></pre>
  
  <p><em>This is the simplest <code>.map</code> which I have, some post methods actually return a rather complex object which map to many new object instances.</em></p>
  
  <p>I see with <code>HttpClient.get</code> you can Type assert the response, can I do something like this with <code>.post</code> so that I don't have to map the data to a new User in each of the subscriptions?</p>
  
  <p><strong>Note:</strong> Eventually I will migrate this again to a better architecture where you actually subscribe to a User variable, but for now I just want to implement HttpClient.</p>