问题
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 });
}
回答1:
HttpClient has generic methods that can be used to provide response type. Http doesn't.
The error means that <Summary[]> generic parameter wasn't expected, and http isn't an instance of HttpClient; likely an instance of 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());
来源:https://stackoverflow.com/questions/50665404/typescript-error-expected-0-type-arguments-for-get-call