Skip to content

Type inference regression with overloads #27972

Closed

Description

TypeScript Version: 3.2.0-dev.20181018

Search Terms:

Code

declare function f<T>(cf: (() => T) | ((x: T) => boolean)): void;

declare function myFn(): Date;
declare function myFn(n: number): void;

f<Date>(myFn); // works
f(myFn); // error

Expected behavior:

No error, as in typescript@3.1.

Actual behavior:

src/a.ts:7:3 - error TS2345: Argument of type '{ (): Date; (n: number): void; }' is not assignable to parameter of type '(() => number) | ((x: number) => boolean)'.
  Type '{ (): Date; (n: number): void; }' is not assignable to type '() => number'.
    Type 'Date' is not assignable to type 'number'.

7 f(myFn); // error

Looks like this was introduced by #27028. Discovered in bluebird on DefinitelyTyped -- in that case it had to do with type CatchFilter<E> = (new (...args: any[]) => E) | ((error: E) => boolean) | (object & E); which unions a construct and call signature which more clearly should be separate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Working as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions