Skip to content

Higher order type inference doesn't work with overloads #33594

Open
@falsandtru

Description

@falsandtru

@ahejlsberg

TypeScript Version: [email protected]

Search Terms:

Code

interface Curried2<a, b, z> {
  (a: a, b: b): z;
  (a: a): (b: b) => z;
}
interface Curry {
  <a, b, z>(f: (a: a, b: b) => z): Curried2<a, b, z>;
}

declare const curry: Curry;

curry(<T extends 0, U extends 1>(n: T, m: U) => n + m)(1)(0);
curry(<T extends 0, U extends 1>(n: T, m: U) => n + m)(1, 0);

Also the following doesn't work:

interface Curried2<a, b, z> {
  (a: a): (b: b) => z;
  (a: a, b: b): z;
}

When removing overloads as follows:

interface Curried2<a, b, z> {
  (a: a, b: b): z;
}

or

interface Curried2<a, b, z> {
  (a: a): (b: b) => z;
}

These work correctly.

Expected behavior:

Infer type parameters correctly and all parameter values are rejected correctly.

Actual behavior:

no error.

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

Labels

SuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions