TypeScript Version: 2.1.6
Code
interfaceFoo{bar(s: string): void;bar(n: number): number;bar(b: boolean): boolean;}typeSN=string|number;varsn1: string|number;varsn2: SN;varfoo: Foo;varx1=foo.bar(sn1);// errorvarx2=foo.bar(sn2);// errorExpected behavior:
This should be allowed.
The type of x1 and x2 should be void | number, the union of the matching overload return types.
All 3 overloads can be seen as a single overload with a union type. It should try to fallback to a union when it can't match one of the originally defined overloads.
Actual behavior:
error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'boolean'.
Type 'string' is not assignable to type 'boolean'.
TypeScript Version: 2.1.6
Code
Expected behavior:
This should be allowed.
The type of
x1andx2should bevoid | number, the union of the matching overload return types.All 3 overloads can be seen as a single overload with a union type. It should try to fallback to a union when it can't match one of the originally defined overloads.
Actual behavior:
error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'boolean'.
Type 'string' is not assignable to type 'boolean'.