【问题标题】:Typescript error for type Array:- Cannot invoke an expression whose type lacks a call signature类型数组的打字稿错误:- 无法调用其类型缺少调用签名的表达式
【发布时间】:2018-11-11 03:38:23
【问题描述】:

我在 Angular5 中使用 typescript 创建了如下 getter-setter:-

  private _locations: Array<string> = [];

  constructor() { }

  /**
   * Getter locations
   * @return {Array<string>}
   */
  public get locations(): Array<string> {
    return this._locations;
  }

  /**
   * Setter locations
   * @param {Array<string>} value
   */
  public set locations(value: Array<string>) {
    this._locations = value;
  }

当我尝试访问方法位置时

this.signUpService.locations();

我收到一个错误:[ts] Cannot invoke an expression whose type lacks a call signature. Type 'string[]' has no compatible call signatures.

【问题讨论】:

标签: javascript typescript angular5


【解决方案1】:

this.signUpService.locations();

getter 未被调用。他们只是得到

修复:

const value = this.signUpService.locations; 

This is just TypeScript saving you.

【讨论】:

    猜你喜欢
    • 2023-03-20
    • 2017-02-03
    • 2017-12-19
    • 2017-07-14
    • 1970-01-01
    • 2017-09-19
    • 2019-09-10
    • 2019-12-15
    • 2018-12-25
    相关资源
    最近更新 更多