【问题标题】:TypeScript : Cannot invoke an expression whose type lacks a call signatureTypeScript:无法调用类型缺少调用签名的表达式
【发布时间】:2017-09-01 13:13:09
【问题描述】:

我是打字稿的新手。基本上我有一个打字稿 GET 函数,我想传递一个 ID 来取回那个特定的记录。我在返回线上收到此错误。我在这里发布之前对此进行了研究,但无法获得接近我的场景的东西。感谢您的帮助!

错误 TS2349 无法调用其类型缺少调用的表达式 签名。

private getRecordRequestUrl = 'http://localhost/Service/api/ReservationRequest/GetRequestById';

 getRecordRequest(RequestId: number): Promise<ReservationModel[]> {
        return this.http.get(this.getRecordRequestUrl(RequestId))
            .toPromise()
            .then(response => response.json().Data as ReservationModel[])
            .catch(this.handleError);
}

【问题讨论】:

  • getRecordRequestUrl 是一个字符串。您正尝试在this.getRecordRequestUrl() 中调用它。正是 TypeScript 警告你的错误类型,它确实存在。

标签: javascript angular typescript


【解决方案1】:

this.getRecordRequestUrl 不是函数,它只是一个字符串。如果你想给它加上RequestId,你应该连接值,例如:return this.http.get(this.getRecordRequestUrl + '/' + RequestId)

【讨论】:

    【解决方案2】:

    getRecordRequestUrl 是一个字符串,而不是一个函数

    但是在return this.http.get(this.getRecordRequestUrl(RequestId)) 行中,您将其称为函数。

    【讨论】:

      猜你喜欢
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 2019-09-28
      • 2019-09-10
      • 2018-12-25
      • 1970-01-01
      • 2015-08-26
      相关资源
      最近更新 更多