-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 2.1.6
Code
interface Foo {
bar(s: string): void;
bar(n: number): number;
bar(b: boolean): boolean;
}
type SN = string | number;
var sn1: string | number;
var sn2: SN;
var foo: Foo;
var x1 = foo.bar(sn1); // error
var x2 = foo.bar(sn2); // error
Expected 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'.
kbtz, robyoder, evil-shrike, seansfkelley, saschanaz and 215 moreloveky, falkenhawk, artemjackson, goliney, amitbeck and 10 more
Metadata
Metadata
Assignees
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript