typesafe-ts API Documentation - v1.7.0
    Preparing search index...

    Type Alias Equal<Left, Right>

    Equal: <T>() => T extends Left ? 1 : 2 extends <T>() => T extends Right ? 1 : 2
        ? true
        : false

    Utility type to check if two types are exactly equal.

    This performs a strict equality check that distinguishes between any, unknown, never, and other types that might seem similar but are actually different.

    Type Parameters

    • Left

      The first type to compare

    • Right

      The second type to compare

    true if the types are exactly equal, false otherwise

    Basic type equality:

    type Test1 = Equal<string, string>;        // true
    type Test2 = Equal<string, number>; // false
    type Test3 = Equal<string, any>; // false
    type Test4 = Equal<unknown, any>; // false

    Structural equality:

    type User = { name: string; age: number };
    type Person = { name: string; age: number };
    type Employee = { name: string; age: number; role: string };

    type Test1 = Equal<User, Person>; // true (same structure)
    type Test2 = Equal<User, Employee>; // false (different structure)

    Union type equality:

    type Test1 = Equal<1 | 2 | 3, 3 | 2 | 1>;     // true (order doesn't matter)
    type Test2 = Equal<true | false, boolean>; // true (equivalent)
    type Test3 = Equal<string | number, any>; // false (any is not a union)

    Use with Assert for compile-time type checking:

    import { Assert, type Check } from "typesafe-ts/assert";

    type ApiResponse = { data: string };
    type ExpectedShape = { data: string };

    // ✅ Passes - types are equal
    Assert<Check.Equal<ApiResponse, ExpectedShape>, "API response shape mismatch">();

    // ❌ Fails - types are different
    Assert<Check.Equal<ApiResponse, { data: number }>, "Wrong data type">();