Skip to content

Overloading arrow function return type should allow union type #33482

Description

TypeScript Version: v3.5.1 (On TypeScript Playground)

Search Terms:

Arrow function overload

Code

const foo1 : {
    (a: number): number;
    (a: string): string;
} = (a: number | string): number | string => a;

// Type '(a: string | number) => string | number' is not assignable to type '{ (a: number): number; (a: string): string; }'.
//   Type 'string | number' is not assignable to type 'number'.
//     Type 'string' is not assignable to type 'number'.

const foo2 : {
    (a: number): number;
    (a: string): string;
} = (a: number | string): number & string => a as any;

function foo3(a: number): number;
function foo3(a: string): string;
function foo3(a: number | string): number | string {
    return a;
}

Expected behavior:

The return value of implementation of overloading arrow function should be number | string which is allowed with function.

Actual behavior:

TypeScript expect the return value of implementation of overloading arrow function should be number & string.

Playground Link:

Link

Related Issues:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions