RxJS observables and generic types for Angular2(Typescript) http wrapper
<p>Today I encountered the following problem while trying to implement an abstract http service. This service should be base to extend for all other http services.</p>

<p>The implementation is following so far, skipping other methods for ilustration:</p>

<pre><code>@Injectable()
export abstract class HttpWrapper&lt;T&gt; {

  private options: RequestOptions;

  constructor(private http: Http, private endpointUrl: string) {
    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    this.options = new RequestOptions({ headers: headers });
  }

  public getAll(): Observable&lt;T[]&gt;{
    return this.http.get(this.endpointUrl, this.options)
      .map(this.extractAll)
      .catch(this.handleError);
  }

  abstract handleError(error: any):Observable&lt;Response&gt;;

  abstract extractOne(res: Response):T;

  abstract extractAll(res: Response):T[];
}
</code></pre>

<p>Now if i want to use the abstract HttpWrapper i do the following:</p>

<pre><code>@Injectable()
export class BlastReportService extends  HttpWrapper&lt;Item&gt; {

  constructor(http: Http) {
    super(http,'/api/items');
  }


  handleError(error: any):Observable&lt;Response&gt;{
    //Handling error
    return Observable.throw(error);
  }

  extractAll(res: Response):Item[]{
    let body = res.json();

    let formatedBody = body.map((item: Item) =&gt; {
      item = new Item(item);
      return blastReport;
    });

    return formatedBody || [{}];
  }
}
</code></pre>

<p>But doing this I get following compilation error:</p>

<pre><code>Type 'Observable&lt;Response&gt;' is not assignable to type 'Observable&lt;T[]&gt;'.
  Type 'Response' is not assignable to type 'T[]'.
    Property 'find' is missing in type 'Response'.
</code></pre>

<p>I can't wrap my head around this because the method extractAll clearly returns Item[] and is used while mapping the results returned from the server.</p>

<p>I decided to implement this abstract HttpWrapper "to stay DRY". I'm not sure if it's the best way to do so. </p>