Closed
Description
TypeScript Version: typescript@3.1.0-dev.20180801
Search Terms: Generic Type Inference Function Parameter Union
Code
interface Foo {
foo: number;
}
declare function acceptUnion(foo: Foo | number): void;
declare var foo: Foo;
declare function erroneouslyExpands<T>(value: T, func: (t: T) => void): T;
// Errors, TS infers the result as `Foo | number`
const test: Foo = erroneouslyExpands(foo, acceptUnion);
Note: This case is common when passing comparators into functions.
Expected behavior:
T
should be inferred as Foo
.
Actual behavior:
T
is expanded based on what func
accepts.
Related Issues: