I will demonstrate my question with a simple example:
class Foo {
foo() { }
}
class Bar {
bar() { }
}
type FooHandler = (arg: Foo) => void;
type BarHandler = (arg: Bar) => void;
type AnyHandler = FooHandler | BarHandler;
declare var handler: AnyHandler;
handler(new Foo()); // Argument of type 'Foo' is not assignable to parameter of type 'Foo & Bar'.
Why does handler only accept the intersection Foo & Bar and not the union Foo | Bar? Is there any way to achieve this?