microsoft / microsoft/TypeScript

Function parameter names are incorrectly inferred from variadiac tuples

Open
#40,452 8 comments 0 reactions 1 assignee View on GitHub

@ahejlsberg is already working on this.

Since Sep 9, 2020.

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

Description

TypeScript Version: 4.1.0-insiders.20200909

Search Terms:
typescript variadic tuple names curry argument
Code

type Curry<A extends unknown[], R> = A extends [infer Head, ...infer Tail] ? (...args: [Head]) => Curry<Tail, R> : R;
declare const curry: <Args extends unknown[], R>(fn: (...args: Args) => R) => Curry<Args, R>;
declare const f: (x: number, y: string, z: boolean) => string;
const g  = curry(f); // incorrectly inferred as (arg_0: number) => (arg_0: string) => (arg_0: boolean) => string;

Expected behavior:
The inferred type should have the correct argument names from f, like (x: number) => (y: string) => (z: boolean) => string;
Actual behavior:
(arg_0: number) => (arg_0: string) => (arg_0: boolean) => string;
Playground Link:
https://tsplay.dev/nWPZJN

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.