microsoft / microsoft/TypeScript

Callback arguments are inferred as any when function has multiple overloads and callback arguments are typed as tuple

Open
#41,709 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

TypeScript Version: 4.0.5 or higher

Search Terms: function overloads, tuples

Code

function f(callback: (...args: [number, string]) => void): void;
function f(callback: (...args: [number, string, boolean]) => void): void;
function f(callback: (...args: any[]) => void): void {}

// demo
f((num, str) => {}); // first signature: ok

f((num, str, bool) => {}); // second signature: all arguments have any type

Expected behavior: num, str and bool should be type of number, string and boolean.

Actual behavior: num, str and bool are type of any

Playground Link:
https://www.typescriptlang.org/play?ts=4.0.5&ssl=3&ssc=32&pln=3&pc=35#code/GYVwdgxgLglg9mABMAFBAhgG0wI3RAawC5EUA6C9AJwHMBnEgbTBAFscBTKgGkTqiowwNALoBKRAF4AfIgBucGABMxJBcoDcAKFCRYCZGiy58xUhTLV6TFuy69+g4bxxw4mDujDips9SrVFJW1daHgkVAxsPEISckpaBkQvAE9GHxl5INUs5UQAbwBfLS0AelLEJQ5WOB0UFFsHAQlMorENRHLkGCp+PhgaMHQoECoOEjgCEtQGtiaeRFd3Ftk2jq66DggEJX7B4dHx5Oxk2jYOMCg6RAALdDkOZLAUxCgUgAcOLSA

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.

Research direction

Reproduce the overload and tuple callback example in the linked TypeScript Playground using the reported version. Trace the compiler's overload resolution and callback-parameter inference, then verify that the three parameters receive number, string, and boolean types rather than any.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.