parth.hirpara
parth.hirpara

Reputation: 542

Typescript error for type Array:- Cannot invoke an expression whose type lacks a call signature

I have created getter-setter as following using typescript in Angular5:-

  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;
  }

When I try to access method locations

this.signUpService.locations();

I am getting an error : [ts] Cannot invoke an expression whose type lacks a call signature. Type 'string[]' has no compatible call signatures.

Upvotes: 3

Views: 644

Answers (1)

basarat
basarat

Reputation: 275927

this.signUpService.locations();

getters are not invoked. They are simply got

Fix:

const value = this.signUpService.locations; 

This is just TypeScript saving you.

Upvotes: 9

Related Questions