2017-09-30 8 views
2

Angular4プロジェクトは、私が実際に理解していないエラーのために構築できません。 @angularからのResponse、Headers、Httpのような私の輸入品を持っています。私は私のプロジェクトをビルドしようとしているとき、私はこのエラーを取得:Angular4とTypeScriptコンパイルエラーTS2453

TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'Response' is not a valid type argument because it is not a supertype of candidate 'Response'. Types of property 'type' are incompatible. Type 'string' is not assignable to type 'ResponseType'.

それは、このコードを参照:

public getPatients(): Observable<any> { 
    //noinspection TypeScriptValidateTypes 
    return this.http.get(AppSettings.API_ENDPOINT + 'patient', { headers: this.getHeaders() }) 
     .map((res:Response) => res.json()) 
     .catch((error) => Observable.throw(error.json().error || "Server error")); 
} 

私は輸入品との回避策を発見し、私はこれらすべてのスレッドで言及したが、それを追加まだ助けにはならない。このようなコードがある場合

+0

あなたは 'http.get()マップ()'のための変数を導入し、あなたのreturn文を分割することができますし、エラーを生成何ラインを教えて:

は、これらを使用してみては?私は 'catch()'の戻り値の推測された型を疑う。 –

答えて

1

私は同じ問題を抱えていました。問題は私が正しいものをインポートしなかったことでした。 。

import {Http, Response} from "@angular/http"; 
import 'rxjs/add/operator/map' 
import 'rxjs/add/operator/catch'; 
import {Observable } from "rxjs/Observable"; 
0

は:

editItem(item: Item) { 
    return this.http.put(`${this.BACKOFFICE_URL}`, item, this.getOptions()) 
     .map((res: Response) => { 
      return res.status === 200 ? res.json() : {}; 
     }) 
     .catch((error: any) => { 
      return Observable.throw(error); 
     }) 
} 

私はあなたのコードを見る唯一の違いは、私は関数に戻り値の型を入れていないということです。

関連する問題