Repository: TypeScript
Issue: Overloaded function args not inferred correctly
Labels: Help Wanted,Possible Improvement

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms

<!--
  What search terms did you use when trying to find an existing bug report?
  List them here so people in the future can find this one more easily.
-->

overload functions 

### 🕗 Version & Regression Information

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to
  https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies:
-->
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about overloading and different function arguments behavior

### ⏯ Playground Link

<!--
  A link to a TypeScript Playground "Share" link which shows this behavior.
  This should have the same code as the code snippet below, and use whichever settings are relevant to your report.

  As a last resort, you can link to a repo, but these will be slower for us to investigate.
-->
[Playground link with relevant code](https://www.typescriptlang.org/play?ts=5.1.3#code/MYGwhgzhAEBC0G8CwAoa7oDMCMAKMATgObYBc0ArgHYDWVA9gO5UCU52A3KhlnoSeWp0mVADTR+AJkG0GzNtElc0GHLgB0m-hHK4A2vzKVZIgLrQAPtAPEjQuWInFpx4c1MsF2S4sTceGMD0VBD0IACm6gAuBGDA4bgsygEYEIwAllHAABbQ+MQQ6hFURFHZLH4qKTzAkOHQZP7V1QThURQEVA3JzYF1iqRNvTyt7Z2KPSkAvkMzKHOooJAwAIKVPADEAEbksJPQQSExFMBR9ASJ69Vl6YXb0AC80FThjHCJ+3M8ACbhS628XZ6ABEOGBpn2ECiYCi6WAVxSAHpEdBwgQCOcIEMeDdCgAHDFnKIATzxkRwjyw1FO6WCeVx5BW4k06m0FWQVV6ow6XVx6m26jULLZ+x4XwwcwWKEOUOg9EpLzeKw+qFQmGpsLpYD4thkblY7GU6qoNK1OoErgc4ikeocCiUao1tK62o0WgKuhsFvsZh8XrsJmY1uctrMnnYPkkCOg3PG2iK4RKZWUUuRqPRmMWwVlWyMJLJ9EwEm8T2Npq6QvdRAg7KGsZdeGFBSSqCl6SoUTRmDi9WA3g5PHy3sDBu6QyHAf1waILh98nIDvmqpQabRGIIWOl2ai0G+Rj7lLLmorjarNej9ac1YTSeyKeX9EFeGwLZQj7U2HEkiSQA)

### 💻 Code

<!-- Please post the relevant code sample here as well. This code and the Playground code should be the same, do not use separate examples -->
```ts
function a1(arg1: unknown): 1;
function a1(arg1: unknown, arg2: unknown): 2;
function a1(...args: ([arg1: unknown] | [arg1: unknown, arg2: unknown])): 1 | 2 {
    return args.length;
}

const b1: typeof a1 = function f1(...args) {
    return a1(...args);
}
```

even simpler is using an interface

```ts
interface a1 {
    (arg1: unknown): 1;
    (arg1: unknown, arg2: unknown): 2;
}

// errors
const b1: a1 = function f1(...args) {
    return args.length;
}
```

### 🙁 Actual behavior

<!-- What happened, and why it was wrong -->

Error: `Target signature provides too few arguments. Expected 2 or more, but got one.`, given the single signature of `b1` above is variadic, and in fact matches the implementation signature of `a1`, one would assume the two functions are equivalent (from a signature perspective)

### 🙂 Expected behavior

<!-- What you expected to happen instead, and why -->

The type of `args` in `b1`  should be inferred as the union of all overloads of `a1` since it is the only way the variadic `args` would satisfy the assigned `typeof a1` requirement.