打字稿错误预期get调用的0个类型实参 [英] typescript error Expected 0 type arguments for get call

查看:60
本文介绍了打字稿错误预期get调用的0个类型实参的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到打字稿错误预期为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,则应转换响应,这是HttpClientHttp之间的少数差异之一:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆