Repository: TypeScript
Issue: never doesn't equal never when never is keys/values from filtering generic object wrapped inside another object by exact value
Labels: Bug

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms
never equals filter mapped type
<!--
  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:
-->

It's broken in all tested versions of typescript (4.1.5 until 4.9.0-dev.20221011 in TS playground). Versions prior 4.1.5 do not support mapped types keys filtering.

### ⏯ 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 minimal code](https://www.typescriptlang.org/play?ts=4.8.4#code/PTAEAsFMBsAdIE4GdRIC4EMFoFA7QJ7ygBqG0ArpEgDwDyokAHmpAHYAmKA9gEYBWkAMZoAfKAC8OUKAbNWnFBjYEA2gF1Q0maAD8s1WwoBbXonXaZALgMBrSAW4AzWRZn4ikUAFEAjhXJaAEEAGlAAIXEJUAAKGgAVURiASklxeMYWdi4IvVAARlAbAAZU+WyUOMSUtNAM8sVQILzCkuTtfTQEKm0bJ0DIPBAIGHhkRk48D2IAMQBLaFYEcIIAZS65tgBzMkpIekyFHL5BESjQAG9tVQBpUE3Qe0cXBgwUPwDoWjpb9TD0BCbLbiBo5LpUfR3GxsSAAN3MNmUBBwAF8hmBCLMFksVutAdtdlQDqCeAJhGJJJccMMZLd7mxHg5nLJQG8fP5AvRfv8NtsQVlGuCvJCiqAYfCEOobD8bhZhmi8JivPNFohIBxCdRiQLjmSztphpt0JAMBxQMzVHRNI4KKAhMpQBQkF4TuTQAB3OZocCshC8L0ILAERkEMLQOb2S5ObjcaVomTRTW0FU4ta8nbkImW9SiUSKzygJzYtUazPUSkpktJmgacTDcWIc22algUAAPV0UyVoErCHVSYAshg0EJwAA5OGIbVHUmnMTaaIfTm9-tl76iMINhB56ZeIuqvulvZIIcj8eThAV4uHwfD0cTiU1nOgYb9L5ed0IbjbFsyDtTIA)

[Playground both keyof and of Values<> cases](https://www.typescriptlang.org/play?ts=4.8.4#code/PTAEAsFMBsAdIE4GdRIC4EMFoFA7QJ7ygBqG0ArpEgDwDyokAHmpAHYAmKA9gEYBWkAMZoAfKAC8OUKAbNWnFBjYEA2gF1Q0maAD8s1WwoBbXonXaZALgMBrSAW4AzWRfxFIoAJJIAcpAA3RBoAFXEJLRlVEM15di5QQ0DzSz1QNAQqVJsnciRIPEJiACFuNHAAQQRIfyCEGgqAGlBi8MjvP2T6ivE4xXTMz1T9H1rg1sYWeJQMrJ0dfVmC+etQXOh87LW85a0izwBRAEcKPIbmiYiAClDRK4BKSXEQyYUE4rSARlAbAAZHvoJG5hB5PUAvQEoCpfH6gf7aRaDbQ5HaFDygY6nDYAdQAluUxggAMJQIS2c4tcLaTFnJqU17TbYbIbzfSlcpVGpdCmtLZLPAgCAweDIRicAVgJC4thCTz4gDkSlAACI2F1laBYAg+NBIMZmidcWS1rimKAAO7cCjQDigMzpbigaqwaAYWUYk55B0erFIPEErok4S2CWgT6Pc1QNigYwYWCwaUAc1AWF4+IQWAI6XRZSgCHS4GUBgA0po0I6nLjoKxqrb7AQULxc6AhBh8igkOArTbtlWAHTuYgAMSrNeKBAAyhkk2RKJBPvQGf0+IIRG0AN7aVTF0DS0D15yyFMoGkbejb9TNdAIJO9Kb9Jb6Hc2NV1dQ2ZQEHAAX1DrfyYY4IKFAAQE5BUDwLiVtWiCQLasbxnB2bwIOngjjBtazhBC5yPeCQrsIYjaIK0roJAGC2oeqh0JojgUC2RYgZ4BEiBa+LgCmCBphkmb7g4zTQLi9igOuTjcNwNh0L+MgRFh1A0OhY6TtObCJnJC7UeooiiGixDQTWcFyUg3wRIpsEcEZGlaaAgqvogoDcCGgqgAAeroeCoaAZmYeB1AALIYGgQjgISOFLvhAiETpMk+mc3mGb5xn0KIzR2QgOmefp5lGQFQUhV0JleaO2WJblwWhTQGjiIK6wAea2qqUBYCue5f5tp4ABMTWgExfENg5UHFbWMZxvAtr7J58UcMWDhJbhbw8JFa7aBEB4uN545TjeqnqZVNEZfsJoYXBM0NoVU2nUlVU2WAaUOU5zVuR5h0XbNZX5XUYWQg5S1ETFp60K9Z3JalXQHeiWW1pd72hZIRXHdNb2BeVBWVdZNU7BaDWJt1LUed1HURlGI3xkmJZlui5ZHQZdazQ5aoDQW1CdQx7aoNwxiQF25oWtwCC2CgAD1AA6AD6VyACMM9yi8AgsDi9Q2bSpam+R1i7fSxYhw5uUQ7nua1Hm2sVnnQF5Xsrd4LQMVBpM+oBpe+5M-m1AGfN1vVgXOkHU+ZJNjchBQKwjRlq-NjKa9FcNGQpivKdtKtzmrmnabpniQwlXsdXDU0h2j1W3V092409k1DRnEEw10ofhYtq5-XDAMx8HiWhyl9tg6nPs+V7ld1FnpllxZpXIx9iBJ+jYBLAWuIoDP93NLwFBoBa4BZviu48LYu4uLm9n-tQnGeGwZS6PcxetYK++gF1wEAfW3vp-Bo1IRNQc05d1ca79kerQ4h4bXHGcqs9paU7o-D+2dB4fzzjddudQi7ORLm-cy0MR6Ek-nhWuUUVrG0BlA2ardQZ1HBnpfBDZe5j0gQjVBeV0EwIxsyLG3BGqINangIAA)

### 💻 Code
So wee need to:
* Wrap generic argument, lets say `O`, in an object(i.e `{anyKey: O}` or just `[O]`).
* Then filter object keys by exact value via `Equals<>` in such a way to pass further empty object.
* Extract keys or values. Since object is empty `never` will be passed.
* And finally compare it with never via  `Equals<>`
<!-- Please post the relevant code sample here as well-->
```ts
// helpers start

type Values<O extends object> =
  O extends any[] 
    ? O[number]
    : O[keyof O]
  
type Equals<A, B> = 
  (<T>() => T extends B ? 1 : 0) extends 
  (<T>() => T extends A ? 1 : 0)
    ? true
    : false

// helpers end

type FilterByStringValue<O extends object> = {
  [K in keyof O as Equals<O[K], string> extends true ? K : never]: any
}

type FilteredValuesMatchNever<O extends object>
  = Equals</*never*/Values</*{}*/FilterByStringValue<[O]>>, never>

type filteredValuesMatchNever = FilteredValuesMatchNever<[]> // false wrong
```

### 🙁 Actual behavior
`filteredValuesMatchNever` is false


### 🙂 Expected behavior
`filteredValuesMatchNever` must be true.
Actually with the `FilterByStringValue` rewritten like this:
```ts
type FilterByStringValue<O extends object> = {
  [K in keyof O as Equals<O[K], string> extends true ? K : never]: O[K]
}
```
`filteredValuesMatchNever`  somehow becomes true

<!-- What you expected to happen instead, and why -->