Repository: TypeScript
Issue: `extends any ?` may return right hand in conditional types
Labels: Needs Investigation

<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨

Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common "Bugs" That Aren't Bugs section!

Please help us by doing the following steps before logging an issue:
  * Search: https://github.com/Microsoft/TypeScript/search?type=Issues
  * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ

Please fill in the *entire* template below.
-->

**TypeScript Version:**  4.0.5

<!-- Search terms you tried before logging this (so others can find this issue more easily) -->
**Search Terms:**
- type inference
- extends any
- conditional types
- right hand

**Expected behavior:**

`type D1 = X1 <O1>` returns `false`.

**Actual behavior:**

In the code below, `type D1 = X1<O1>` seems to return `false`, but it actually returns `true`.
If you change the seemingly irrelevant right-hand type in `extends any ?` written for union distribution to `undefined`, it will behave as intended.

<!-- Did you find other bugs that looked similar? -->
**Related Issues:**

**Code**
```ts
type X1<T> = IfEq<
  AllKeys1<T>,
  keyof T,
  true,
  false
>;

type X2<T> = IfEq<
  AllKeys2<T>,
  keyof T,
  true,
  false
>;

type IfEq<X, Y, T, E> = [X] extends [Y] ? ([Y] extends [X] ? T : E) : E;

// AllKeys<{ x: ... } | { x: ...; y: ... }> -> "x" | ("x" | "y") -> "x" | "y"
type AllKeys1<O extends Object> = O extends any ? keyof O : never;
type AllKeys2<O extends Object> = O extends any ? keyof O : undefined;

type O1 = { x: string; y: number } | { x: boolean; z: number }
type A1 = AllKeys1<O1> // "x" | "y" | "z"
type A2 = AllKeys2<O1> // "x" | "y" | "z"
type B = keyof O1 // "x"

type C1 = IfEq<A1, B, true, false> // false
type C2 = IfEq<A2, B, true, false> // false
type D1 = X1<O1> // true ???
type D2 = X2<O1> // false

type O2 = { x: string; y: number } | { x: boolean; y: Object }
type E1 = X1<O2> // true
type E2 = X2<O2> // true
```



<details><summary><b>Output</b></summary>

```ts
"use strict";

```


</details>


<details><summary><b>Compiler Options</b></summary>

```json
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}
```


</details>

**Playground Link:** [Provided](https://www.typescriptlang.org/play?#code/C4TwDgpgBAGgjAHgCoD4oF4oEkBmBRARwQFgAoKKAQQBtqBpCEAZ0VQBoyKBrRgexyhIO5KMABOAVwjCKOAIbUmEMigDcZMqEiwATMjSZchEiJr1GTPe05QeIfoJmjJ0m-MXLSajaS3QjRDBsUACawUJQeAZQANowALpQEAAewBAAdgAmTLEhiQD8UAAUMXlJqRnZsQlQhUhQAFyRAJSNkeqkZAD0XVS0DMwIAN5QyU0AdJNQAL5QAD5QI2NQk+OqUCATU9NoALRoAETJB-PFRycLByAHrftQ56dXB5rg0GYDLAgA8uVpWTlfABGACsIABjYDRH4pP5VOTpEC1Wx8AQ-JrpCAANwgYg6fj65mYemhFX+UCBoIhUN+lRy8MRhTsDjRUAkWQgOAAlhjMh0XtovnAMItRk0mOJuQBzdabKDpCQAW0BOJmpyWTUBvF41Ag8PWAC90YrlWIZvy3kLMO8LIhBWgevdjo9ro99c9fK8qDphdaid84Pbeg9Li7Lm7zVAAELCpmooUO84+fEAYUt2HwREocGCkeC4ikwXcSkDUCLnhT3sMGYQlB0ObzLkLCmLUAdZYjABE0-B-SX89B8oPO5XdL3W71250PQKR+qoOKxFKZUalSrZgs55rtbr0svySDwcAzdPoHhu7adH2XBG8COYMTL+PnFIgA)