Repository: TypeScript
Issue: Inferring less information for generics in 4.2+ compared to previous versions
Labels: Needs Investigation,Rescheduled

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

infer used as the value of a generic no longer infers the actual value, but it infers the default value of that generic argument.

### 🔎 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.
-->

infer, unknown, default, generic

possibly similar issues?

https://github.com/microsoft/TypeScript/issues/43161
https://github.com/microsoft/TypeScript/issues/42939

### 🕗 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 changed between versions **4.1.5** and **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 in 4.2.3](https://www.typescriptlang.org/play?ts=4.2.3#code/C4TwDgpgBAygFgQ0lAvFA3gWAFBSgawhAC4oAlCAYwHsAnAEwB4BnYWgSwDsBzAGigCunfJ2oB3TgD4A3DgC+s7DlDJ4SCAGFaEBMDqMAKlAgAPYBE71msRJEmooACkoAjUo9a6IpAwG0A5IQg-gC6AJSo9gBu1Oz0ESjRsfSKyuDQAKJmtAiUwGqQhvZoRqbmltYFmtq6+lwAZhC0UAZV9gD8LVVQpJwQUU2p2CrQMMBe3WhYuAREpOhQADYQwOa0pKwcPFAK8oojsOPmVVo6es1oJzXnjGMTthAyODg0nKxQYrTUPFWkWWy5fIPW5HCBXM50YoYHB4ILzGF4KAAeiRUAAAsBmABaUyQPI42hfWgIvDLVZNUgAJl4CLkNOwCiAA)
[Playground link with relevant code in 4.1.5](https://www.typescriptlang.org/play?ts=4.1.5#code/C4TwDgpgBAygFgQ0lAvFA3gWAFBSgawhAC4oAlCAYwHsAnAEwB4BnYWgSwDsBzAGigCunfJ2oB3TgD4A3DgC+s7DlDJ4SCAGFaEBMDqMAKlAgAPYBE71msRJEmooACkoAjUo9a6IpAwG0A5IQg-gC6AJSo9gBu1Oz0ESjRsfSKyuDQAKJmtAiUwGqQhvZoRqbmltYFmtq6+lwAZhC0UAZV9gD8LVVQpJwQUU2p2CrQMMBe3WhYuAREpOhQADYQwOa0pKwcPFAK8oojsOPmVVo6es1oJzXnjGMTthAyODg0nKxQYrTUPFWkWWy5fIPW5HCBXM50YoYHB4ILzGF4KAAeiRUAAAsBmABaUyQPI42hfWgIvDLVZNUgAJl4CLkNOwCiAA)

### 💻 Code

<!-- Please post the relevant code sample here as well-->

```ts
type Shape = {
  key: Record<string, unknown>;
};

type ShapeCreator<T extends Shape> = (cb: (state: T['key']) => void) => void;

type ExtractShape<T> = T extends ShapeCreator<infer TShape> ? TShape : never;

type StateShape = {
  key: { letter: string };
};
type StateShapeCreator = ShapeCreator<StateShape>;

const wrongShape: ExtractShape<StateShapeCreator> = {
  key: {
    // @ts-expect-error
    letter: 2,
  },
};
```

### 🙁 Actual behavior

<!-- What happened, and why it was wrong -->

the inferred value is the default of the generic

### 🙂 Expected behavior

<!-- What you expected to happen instead, and why -->

the inferred value is the actual value of the generic, like it used to do.