title: Angular HttpClient, setting map type dynamically
body: <p>I have a method on an service to handle all backend requests. Instead of writing a whole bunch of different calls using the HttpClient, I thought I might write one single function that could connect to my backend and pass it arguments to handle different types of data.</p>
  
  <p>Consider this function</p>
  
  <pre><code>public postRequest(token: string, url: string, body: any, headers: Object = {}) : Observable&lt;any&gt; {
  //create new header object
  const httpOptions = {
    headers: new HttpHeaders()
      .set('Authorization', token)
  };
  //add the headers if any
  for(let index in headers){
    httpOptions.headers.set(index, headers[index]);
  }
  //connect to the backend and return the repsonse
  return this.http.post( this.config.BASE_SERVER_URL + url, body , httpOptions)
    .pipe(
      map((res) =&gt; {
        return res;
      }),
      catchError(this.handleError)
    );
  }
  </code></pre>
  
  <p>It works well except I wanted to be able to set the response type dynamically. Thus I could set the method to use one of my model types.</p>
  
  <p>Here's what I'm trying to accomplish. Hopefully this makes sense.</p>
  
  <pre><code>map(res: "Attendee") =&gt; {}
  //or
  map(res: typeof(typeInput)) =&gt; {}
  </code></pre>
  
  <p>Is it possible to pas a "dynamic" type to the http map method so I can map the different responses to a model of my choice?</p>