3

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.

3
  • Can u post the code for accessing method 'locations' ? Commented Jun 1, 2018 at 4:01
  • like this from another component :- this.signUpService.locations(); Commented Jun 1, 2018 at 4:05
  • 1
    possibly the duplicate of stackoverflow.com/questions/39691889/… Commented Jun 1, 2018 at 4:08

1 Answer 1

9

this.signUpService.locations();

getters are not invoked. They are simply got

Fix:

const value = this.signUpService.locations; 

This is just TypeScript saving you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.