【发布时间】:2017-12-30 10:20:09
【问题描述】:
使用 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);
}
我错过了什么?
【问题讨论】:
-
Response的分型版本存在冲突,很可能是由于导入了一些使用不同版本的@angular/http或类似内容的库。 -
谢谢@torazaburo,完全忘记导入响应了!必须弄清楚这些。
标签: angular http typescript observable