타입 별칭으로도 오버로딩을 표현할 수 있습니다. 각각의 함수 타입을 선언한 뒤 & 연산자로 하나로 묶으면 오버로딩과 같은 역할을 합니다.

    type Add1 = (x: number, y: number) => number;
    type Add2 = (x: string, y: string) => string;
    type Add = Add1 & Add2;
    const add: Add = (x: any, y: any) => x + y;
    
    add(1, 2); // 3
    add('1', '2'); // 12
    add(1, '2');
    add('1', 2);
    // No overload matches this call. Overload 1 of 2, '(x: number, y: number): number', gave the following error. Argument of type 'string' is not assignable to parameter of type 'number'. Overload 2 of 2, '(x: string, y: string): string', gave the following error. Argument of type 'number' is not assignable to parameter of type 'string'.
    
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.