Skip to content

Unexpected union inference because of generic function argument #16107

Closed
@gcnew

Description

@gcnew

TypeScript Version: nightly (2.4.0-dev.20170502)

TypeScript improperly infers a union type when a generic function is used as an argument. Such an inference is unexpected unless the union constituent is present, or the type arguments are manually provided by the programmer.

Code

declare function sameType<T>(x: T, y: T): T;
declare function test<R>(f: (x: string, y: number) => R): void;

test(sameType); // bad inference: R = string | number

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeBugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions