打字稿错误预期get调用的0个类型实参 [英] typescript error Expected 0 type arguments for get call
问题描述
我收到打字稿错误预期为0个类型实参,但返回get调用的行却得到1个.我的接听电话怎么了?
I am getting typescript error Expected 0 type arguments, but got 1 for line that returns get call. What is wrong with my get call?
public get(params: SummaryParams): Observable<Summary[]> {
const uri = `${this.config.URLS.LOAD_SUMMARY}`;
const params = new HttpParams()
.set('startDate', params.startDate.toString())
.set('endDate', params.endDate.toString())
.set('userId', params.userId);
return this.http.get<Summary[]>(uri, { params });
}
推荐答案
HttpClient
具有可用于提供响应类型的通用方法. Http
没有.
HttpClient
has generic methods that can be used to provide response type. Http
doesn't.
该错误表示未预料到<Summary[]>
通用参数,并且http
不是HttpClient
的实例;可能是Http
的实例.
The error means that <Summary[]>
generic parameter wasn't expected, and http
isn't an instance of HttpClient
; likely an instance of Http
.
如果应用程序使用Angular 4.3或更高版本,则应将Http
替换为HttpClient
.如果应使用Http
,则应转换响应,这是HttpClient
和Http
之间的少数差异之一:
If the application uses Angular 4.3 or higher, Http
should be replaced with HttpClient
. In case Http
should be used, a response should be transformed, this is one of few differences between HttpClient
and Http
:
return this.http.get(uri, { params })
.map(res => <Summary[]>res.json());
这篇关于打字稿错误预期get调用的0个类型实参的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!