Skip to content

Type inference regression with overloads #27972

Description

TypeScript Version: 3.2.0-dev.20181018

Search Terms:

Code

declarefunctionf<T>(cf: (()=>T)|((x: T)=>boolean)): void;declarefunctionmyFn(): Date;declarefunctionmyFn(n: number): void;f<Date>(myFn);// worksf(myFn);// error

Expected behavior:

No error, as in typescript@3.1.

Actual behavior:

src/a.ts:7:3-errorTS2345: Argumentoftype'{ (): Date; (n: number): void; }'isnotassignabletoparameteroftype'(() => number) | ((x: number) => boolean)'.Type'{ (): Date; (n: number): void; }'isnotassignabletotype'() => number'.Type'Date'isnotassignabletotype'number'.7f(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.

Metadata

Metadata

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