Repository: TypeScript
Issue: Type inference behaves unexpectedly when dealing with functions that have type parameters
Labels: Help Wanted,Possible Improvement

# Bug Report

When a function definition a with type parameters is passed as an argument to another function b, b is unable to destructure the parameters of the passed a function.

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms

type parameter function argument destructure

<!--
  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.
-->

### 🕗 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 generics

### ⏯ 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.0-beta#code/C4TwDgpgBAIhBmBDArgG2ANUQJwJaIDtgAFbAezAGcoBeKAbwCgophEAjSgYVUUsoByiALYQA-AC4olYHgIBzRgF9GjeMgIBjYLjIEo8AgB5iUCAA9gEAgBNq9JQD4AFDnkBGSVGdhyVKcQAlLSOUABuZLg2gQEMzFDYEMDI2PoEaKhQfFkEIMqqmnoyWbQGBM7pqJnZhCBZ1D5+lFJwSGiYOPhEpBSUwTShEVGBjIUExeylhhUZ9Tl12UYAKi6+vS0IKOhYeIQkTf2DkdGqiAB0bJw8fIIiEIzsFxzcvPxCoqqgkFBL7qWN61gm3aOy6+16h3Cx0YX2gSwATKVlqsmhs2ttOnselRIUMbJ9wHCAMylYg4O5WbCUZbuRwAbQADABdOkAckuLxu7wgrKZMMJPwALKTyaJKdSEfTmWyOdc3ndeYwgA)

### 💻 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
type DefaultVariantProps = {
  tabsClassName?: string
}

function fn<P extends {}>(arg1?: (props: P) => void): P {
  return null as any
}

const a = fn(null as any as (props: DefaultVariantProps) => void)
const b = fn(null as any as <T>(props: DefaultVariantProps) => void)

// no problem
a.tabsClassName
// Property 'tabsClassName' does not exist on type '{}'.(2339)
b.tabsClassName

type T1 = (props: DefaultVariantProps) => void
type T2 = <T>(props: DefaultVariantProps) => void

// no problem
type T3 = Parameters<T1>[0]['tabsClassName']
// no problem
type T4 = Parameters<T2>[0]['tabsClassName']
```

### 🙁 Actual behavior

<!-- What happened, and why it was wrong -->

When a function definition a with type parameters is passed as an argument to another function b, b is unable to destructure the parameters of the passed a function.
It seems that generics should not cause type inference failures.

### 🙂 Expected behavior

<!-- What you expected to happen instead, and why -->

No error.