flow
flow copied to clipboard
Function overloading does not work if one of the arguments is a union
In the examples below, foo, bar and baz are conceptually same functions, each taking two arguments, and each of those arguments can be either a number or a string.
Flow is perfectly happy with foo and baz, but complains about function bar.
declare class Test {
static foo(one: number, two: number): void;
static foo(one: number, two: string): void;
static foo(one: string, two: number): void;
static foo(one: string, two: string): void;
static bar(one: number|string, two: number): void;
static bar(one: number|string, two: string): void;
static baz(one: number|string, two: number|string): void;
};
Test.foo(1, 1);
Test.foo(2, "two");
Test.foo("one", 2);
Test.foo("one", "two");
Test.bar(1, 1);
Test.bar(2, "two");
Test.bar("one", 2);
Test.bar("one", "two");
Test.baz(1, 1);
Test.baz(2, "two");
Test.baz("one", 2);
Test.baz("one", "two");
This, like #796, is also a manifestation of #583. Thank you for showing us how far-reaching this issue is. I'm just linking these issues together so we can close them all out once we come up with a good fix.
Seems to have been fixed some time back.