typescript error Expected 0 type arguments for get call

≯℡__Kan透↙ 提交于 2020-01-04 09:21:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!