Repository: TypeScript
Issue: KnownKeys<T> breaking change in 4.3.1-rc
Labels: Bug,Domain: Conditional Types,Fix Available,Rescheduled

# 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.
-->

KnownKeys, never, getting known interface keys

### 🕗 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.3.0-beta and 4.3.1-rc

### ⏯ 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.
-->

- [4.3.0-beta playground](https://www.typescriptlang.org/play?ts=4.3.0-beta#code/C4TwDgpgBA0gdgewO5xhEBnAPAFQHxQC8UA3gFBRQDaMUAlnFANboIBmUOAugFxQbAATgwDmUCAA9gEOABMMsKAH4ocCADcIgqHzgBXALYAjLeKkz5ilWs3a+MMgF8z0uQpLUA+vUYsQ7Tl4fNlMAVShnFXDdDS0AbjJEhmlBNgBDAGNoAAk0jABlIVE0TFIKagw+AWE4ESC0uBAExyS4FPSszgALUQB1OmAukoVJV0tcgqLa4bLKNgQEPj04JkQUBMojNMEllbW4ZsSMhDgBKFkIA0XYfeHcHtr+weGCYgByeYQ3uKA) – types work.
- [4.4.0 playground](https://www.typescriptlang.org/play?ts=4.4.0-dev.20210518#code/C4TwDgpgBA0gdgewO5xhEBnAPAFQHxQC8UA3gFBRQDaMUAlnFANboIBmUOAugFxQbAATgwDmUCAA9gEOABMMsKAH4ocCADcIgqHzgBXALYAjLeKkz5ilWs3a+MMgF8z0uQpLUA+vUYsQ7Tl4fNlMAVShnFXDdDS0AbjJEhmlBNgBDAGNoAAk0jABlIVE0TFIKagw+AWE4ESC0uBAExyS4FPSszgALUQB1OmAukoVJV0tcgqLa4bLKNgQEPj04JkQUBMojNMEllbW4ZsSMhDgBKFkIA0XYfeHcHtr+weGCYgByeYQ3uKA) – types fail. This issue also exists in 4.3.1-rc but that version isn't in the playground.

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```ts
type KnownKeys<T> = {
  [K in keyof T]: string extends K ? never : number extends K ? never : K
} extends { [_ in keyof T]: infer U } ? U : never;


interface HasStringKeys {
  [s: string]: any;
}

interface ThingWithKeys extends HasStringKeys {
  foo: unknown;
  bar: unknown;
}

const demo: KnownKeys<ThingWithKeys> = 'foo';
```

### 🙁 Actual behavior

`demo` has type `never`.

### 🙂 Expected behavior

`demo` has type `'foo' | 'bar'`.

### Other info

I'm not sure where I got `KnownKeys` from, but it appears on https://stackoverflow.com/a/51956054/123395.

This issue impacted https://www.npmjs.com/package/idb, but I've already worked around the issue by using the other method on that StackOverflow post. https://github.com/jakearchibald/idb/commit/e3c76a59f6ab461b03ceabebc24dea826a074a76