Repository: TypeScript
Issue: Cannot infer `thisArg` argument type of `Function.bind` for functions with a `this` type consisting of generic functions
Labels: Bug

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->
Consider a function like-
```ts
declare function callback<T>(this: CallbackCtx<T>): void;
```
Where `CallbackCtx` is an object containing generic function(s)-
```ts
interface CallbackCtx<T> {
    onsuccess: (x: T) => number;
    onerror: (err: any) => void;
}
```
For such a function, that has its `this` type set to an object containing generic function(s), `Function.bind` cannot infer the type of `thisArg` (from the first overload) correctly.

If the type parameter to `.bind` is explicitly specified (by substituting the generic function type to be a concrete type) - it works fine.

The type of `thisArg` inferred by typescript automatically, is `CallbackCtx<unknown>`.

It should be noted that if `CallbackCtx` contains only non function-like property(s) - the types are inferred correctly. As seen [in this playground](https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgMJwDYYEaINapgAeAPACoB8yA3gLABQyTyMA9qwFzJkMC+DDACYQEGOFBQwAriARhgrEMgSYc+chQAUYABbAAzl3RZcCAsQ0BKLgDdWwQQG4B9YaPEoEi-WGXEjqqbmpD5QoADmFM70DCom+AB02KCCmnJEltFAA)

### 🔎 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.
-->
bind, generic, function

### 🕗 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:
-->
4.2.3

### ⏯ Playground Link

<!--
  A link to a TypeScript Playground "Share" link which shows this behavior

  The TypeScript Workbench can be used for more complex setups, try
  https://www.typescriptlang.org/dev/bug-workbench/

  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?#code/JYOwLgpgTgZghgYwgAgMJwDYYEaINapgAeAPACoB8yA3gLABQyTyA9iAM4CuCS77AXMgAURQWQCUyALxUQnALbZoAbgbNWIaFBZRBQrYLggAnpJnIAbi2AATVfQC+DBjYgIMcKChicQCMMBsyAiYOPjkFEJgABbAAmihuAgExBHigla29i5uHl7BbOxgwcSC6FhJKaRFUKAA5hTZ9CEV+AB02KA2Qv5E4vYA9APIAHoJrcmE1WC1IA3IccggLMVwfMB1IHDYGChgLONhk6m+eMsA7iAUzs2J7Z0gNiRRsfHlR1UkNfUUZlSZNkivX6DCGo2QAHUdHh2MgYKAUOdohAQMh5EZOKFjMguNgisAwJwAnNkDEUHUUdBgAhScYAA4oFgwUnIuG+fyBEAMIA)

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```ts
interface CallbackCtx<T> {
    onsuccess: (x: T) => number;
    onerror: (err: any) => void;
}

declare function callback<T>(this: CallbackCtx<T>): void;

declare const ctx: CallbackCtx<string>;

callback.bind(ctx);
// ^ CallbackCtx<string> is not assignable to CallbackCtx<unknown>

callback.bind<(this: CallbackCtx<string>) => void>(ctx);
// ^ Works fine when manually substituting the generic type of the function

```

### 🙁 Actual behavior

<!-- What happened, and why it was wrong -->
The line `callback.bind(ctx);` produces errors

### 🙂 Expected behavior

<!-- What you expected to happen instead, and why -->
The line `callback.bind(ctx);` should infer the type of `callback` correctly by substituting the generic type with the help of the type of `ctx` and should not produce errors