ts-type-forge
    Preparing search index...

    Type Alias TypeEq<A, B>

    TypeEq: <T>() => T extends A ? 1 : 2 extends <T>() => T extends B ? 1 : 2
        ? true
        : false

    Checks if two types A and B are exactly the same.

    This utility uses a technique involving conditional types within function types to determine type equality. It returns the boolean literal true if A and B are identical types, and false otherwise.

    Type Parameters

    • A

      The first type to compare.

    • B

      The second type to compare.

    true if A and B are the same type, false otherwise.

    type T1 = TypeEq<string, string>; // true
    type T2 = TypeEq<string, number>; // false
    type T3 = TypeEq<{ a: number }, { a: number }>; // true
    type T4 = TypeEq<{ a: number }, { b: number }>; // false
    type T5 = TypeEq<any, string>; // false (usually, depends on TS version specifics)
    type T6 = TypeEq<never, never>; // true
    type T7 = TypeEq<string | number, number | string>; // true