Type Alias IsEqual<A, B, Then, Else>

IsEqual<A, B, Then, Else>: [A, B] extends [B, A]
    ? BothNever<A, B, Then, Else, BothAny<A, B, Then, Else, IdentityEqual<A, B, Then, And<IsObject<A>, IsObject<B>, IdentityEqual<Properties<A>, Properties<B>, [A, B] extends [((...args: infer P1) => any), ((...args: infer P2) => any)]
        ? IsEqual<P1, P2, Then, Else>
        : Then, Else>, [A, B] extends [B, A]
        ? Then
        : Else>>>>
    : And<IsSymbol<A, {
        distributive: false;
    }>, IsSymbol<B, {
        distributive: false;
    }>, Then, Else>

Checks A and B are equal.

type R = IsEqual<1, 1> // true
type R = IsEqual<any, any> // true
type R = IsEqual<boolean, boolean> // true
type R = IsEqual<true, true> // true
type R = IsEqual<[1], [1]> // true

type R = IsEqual<boolean, true> // false
type R = IsEqual<any, 1> // false
type R = IsEqual<[any], [1]> // false
type R = IsEqual<{ a: 1 }, { a: 1; b: 2 }> // false

Note that intersection type checks only works at first level. It cannot be check recursively, or else will run into infinite recursion if the type includes recursive types.

Type Parameters

  • A
  • B
  • Then = true
  • Else = false