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:
TypeScript Version: v3.5.1 (On TypeScript Playground)
Search Terms:
Arrow function overload
Code
Expected behavior:
The return value of implementation of overloading arrow function should be
number | stringwhich 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: