Repository: TypeScript
Issue: incorrect result with conditional type and boolean
Labels: Needs Investigation,Rescheduled

**TypeScript Version:**  4.0.2

**Search Terms:**

"conditional type" "boolean" "incorrect result"

**Code**

```ts
type HasKey<T, K> = K extends keyof T ? true : false
type SimpleNot<X extends boolean> = X extends true ? false : true
type SimpleAnd<A, B> = A extends true ? B extends true ? true : false : false
type IsDisjointSimple<A, B> = SimpleAnd<SimpleNot<HasKey<A, keyof B>>, SimpleNot<HasKey<B, keyof A>>>

type If<Cond extends boolean, Then, Else> = Cond extends true ? Then : Else
type Equal<A, B> =
  (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2)
  ? true : false
type And<A extends boolean, B extends boolean> = If<
  Equal<A, true>,
  B,
  If<
    Equal<B, true>,
    A,
    If<
      Equal<A, boolean>,
      If<Equal<B, boolean>, boolean, false>,
      false
    >
  >
>
type Not<X extends boolean> = If<
  Equal<X, boolean>,
  boolean,
  If<Equal<X, true>, false, true>
>
type IsDisjoint<A, B> = And<Not<HasKey<A, keyof B>>, Not<HasKey<B, keyof A>>>

type Foo = { a: 1 }
type Boo = { b: 1 }

// false - correct
type fooHasBooKeys = HasKey<Foo, keyof Boo>

// true - correct
type fooNoBooKeysSimple = SimpleNot<HasKey<Foo, keyof Boo>> 

// true - correct
type isFooBooDisjointSimpleRaw = And<SimpleNot<HasKey<Foo, keyof Boo>>, SimpleNot<HasKey<Boo, keyof Foo>>> 

// true - correct
type isFooBooDisjointSimple = IsDisjointSimple<Foo, Boo>

// true - correct
type fooNoBooKeys = Not<HasKey<Foo, keyof Boo>>

// true - correct
type booNoFooKeys = Not<HasKey<Boo, keyof Foo>>

// true - correct
type isFooBooDisjointRaw = And<Not<HasKey<Foo, keyof Boo>>, Not<HasKey<Boo, keyof Foo>>> 

// false - wrong
// this should be identical to `isFooBooDisjointRaw`.
// The type is exactly the same.
type isFooBooDisjoint = IsDisjoint<Foo, Boo> 
```

The type utilities `HasKey`, `If`, `Equal`, `And`, `Not` are unit tested in https://github.com/unional/type-plus/pull/71 and should be working as expected.

**Playground Link:**
[playground](https://www.typescriptlang.org/play?#code/C4TwDgpgBAEghgZwNIRAHgCoBopIHxQC8uUEAHsBAHYAmCUA1qgPYBmUGUA-FMAE4BXaAC4orOABsEEAFChIUAMoBLALZgJEAHLNgaABqkK1OlABGzZprhUCxQ+Uq16-IdzGTpUUa9nzoKuqaAIK0aME4AEJ2UMFGTqa+7pHxJi6C0DxJouJSIh55cuDQAJIIACLKCABWzMpUwIEaEOFRMU0hYR3aumjwyKitjCzs0Xg43Tp6-SjokThMIGyxeKsyRQolrGgAwsy0qc7mltZUOBgAFtQ4AKJ5MXsHjmm8Ge6X1N5Qd9Ib0DcARwEkiG0SIMigUAAFJg8FCAJREAicZ5HOI8ACMXwATIjUaYYRg4YjCMjDqYUpicfCIe5sgVfv5YmE4vj6BYrBAbFFyeyTlzbEQoFs0LTAcCJENfONafNaSLaZDxSD5q8hDLIZCIorhdsdUqgSCIsdOTYNZrISLlZLVRzTuMTaccLlpOaLS7ZBa8LTvd6mVMDLzHQKYgqDRKDDg7SGsLTo9z5dtrZG1RAHR6cNKZH7isKKlVavU9MawcRQjQ0AGZoNjYtlmMcFXELM0Kq6+xgqtvX8oAAxSxCgDeUDgoixAF8e5EB8Rh2Yx1BJzIAPTLhnQAC0UAAxsw+HwINvgD3WJZ+tPmLN6MRq+h+8wFiMoBfu6vU1At7v94fj0zT8wdAvK9uiFSZelvNB70fJZRksVYoHWN8kk-PcDyPHsqnvC9KhqOoGm6AAlOAAHchXLNAwOmZtBig4YYOfOCHUovpqLmSxoOWe8uwQlc12QndUJ-DCECwywcMLfC1GaIUynEvDGikzRIPYhjmFfPi3hQ790L-SxAMsK8hSbAY7xU9tVLWXj3y0tDf1zDkdHvQziGMlsLw49guPU6yBO0uyFEwyxsILeSiNIsswlcmizKfF8HSitiHzozjGIIRC1w9D8oGIvh9gAcys4ALiqKAEAuZgBAkGhzGgZQaGoYBlG3SReGYKAAANAuYYLcKLML2oAOisj5eFzEryDgI8JBAXgrlKuBVAgIamS6nqJOAGT816hplKSl8EKAA)


**Related Issues:**