microsoft / microsoft/TypeScript

Higher order type inference doesn't work with overloads

Open
#33,594 6 comments 2 reactions 1 assignee View on GitHub

@ahejlsberg is already working on this.

Since Sep 25, 2019.

Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

@ahejlsberg

TypeScript Version: typescript@3.7.0-dev.20190925

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:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.