使用Angular2 / 4并处理服务,但我不确定为什么会出现这种类型的错误。我相信我正确地设置了我的类型,但这显然是错误的....
错误:
ERROR in C:/Users/rutherfordc.AA/Documents/GitHub/Sweeper/src/app/people.service.ts (19,12): The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the t
ype 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'.
这是导致根据错误抛出错误的代码。 (为了完整性添加了额外的行。)
person:Person = new Person();
private dataRetrievalUrl: string = '/api/';
constructor(private http: Http) { }
public getPersonById(id: string):Observable<Person>{
var fullUrl: string = this.dataRetrievalUrl + id;
return this.http.get(fullUrl)
.map(this.extractData)
.catch(this.handleError);
}
我错过了什么?
答案 0 :(得分:0)
catch
中的.catch(this.handleError);
正在更改导致类型不匹配的返回类型。因此错误。