타입스크립트 인터페이스에 메서드를 등록하는 방식이 두 가지가 있다.
Method Declaration
interface MyInterface {
myFunction(name: string): string
myFunction(age: number): number
}
타입스크립트 인터페이스에서는 메서드의 오버로딩이 가능하다.
오버라이딩은 존재하지 않는다. 왜냐하면 메서드의 바디는 구현하지 않기 때문이다.
오버라이딩 / 오버로딩
오버라이딩은 메서드의 이름, 인자, 리턴 타입이 같고 함수 내용만 다르다.
오버로딩은 메서드의 이름만 같고 인자, 리턴타입 중 하나만 바뀌어도 오버로딩이다.
Function Properties
interface MyInterface {
myFunction: (name: string) => string
myFunction: (age: number) => number // 에러
}
// 에러: Duplicate identifier 'myFunction'