devtypes - v1.1.0
    Preparing search index...

    Type Alias IfEquals<X, Y, A, B>

    IfEquals: <T>() => T extends X ? 1 : 2 extends <T>() => T extends Y ? 1 : 2
        ? A
        : B

    Conditional type based on type equality.

    Type Parameters

    • X

      First type to compare

    • Y

      Second type to compare

    • A = X

      Type returned if X and Y are equal (defaults to X)

    • B = never

      Type returned if X and Y are not equal (defaults to never)

    1.1.0

    Resolves to one of two branches depending on whether two types are equal. Internal implementation uses function signature variance for comparison. This approach works well for most practical structural equality checks.

    type A = IfEquals< string, string, number, boolean >; // number
    type B = IfEquals< string, number, number, boolean >; // boolean