웹사이트 검색

javascript - Typescript 타입 Array에 대한 오류: 호출 시그니처가 없는 표현식을 호출할 수 없습니다


다음과 같이 Angular5에서 TypeScript를 사용하여 게터-세터를 생성했습니다:-

  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] 호출 서명이 없는 타입의 표현식을 호출할 수 없습니다. 타입 'string[]'에는 호환되는 호출 서명이 없습니다.

답변 #1

this.signUpService.locations();

getter는 호출되지 않습니다. 단순히 얻어집니다

수정 :

const value = this.signUpService.locations; 

이것은 단지 TypeScript가 여러분을 구하는 것입니다.

관련기사