0
입력 된 스크립트에서 메소드가 어떻게 오버로드됩니까? 다음 코드를 감안할 때 인터페이스를 구현하는 클래스가 있습니다. 인터페이스 'polymorhpic'메서드가 있지만 그들을 구현할 것 - 오류 "중복 식별자 'MyMethod'가져 오는 것. 나는이 문제를 해결하기 위해 관리했습니다타이프 스크립트에서 메서드를 오버로드하는 방법은 무엇입니까?
export class IService {
MyMethod(): string;
MyMethod(value: string): number;
}
export class MyService implements IService {
MyMethod(): string { return "hello world;" }
MyMethod(value: string): number { return 1; }
}
내가 거기 아시다시피 타이프 스크립트에서는 그렇게 할 수 없습니다. 선택적 매개 변수 'MyMethod (param : string = "")를 사용하여 단일 메서드를 만들 수 있습니다. 문자열 { if (param == "") \t return 1; else return "hello world"; }' –
예, 문제는 인터페이스를 사용하지 못하게하는 것입니다. – MarzSocks