Type Alias IsExact<T, U>

IsExact<T, U>: ParametersAndReturnTypeMatches<FlatType<AnyToBrand<T>>, FlatType<AnyToBrand<U>>> extends true
    ? ParametersAndReturnTypeMatches<FlatType<DeepPrepareIsExact<T>>, FlatType<DeepPrepareIsExact<U>>> extends true
        ? true
        : false
    : false

Checks if type T exactly matches type U.

Type Parameters

  • T

    The type to check if it exactly matches type U.

  • U

    The type to check if it exactly matches type T.

import { assertType, IsExact } from "@std/testing/types";

assertType<IsExact<string | number, string | number>>(true);
assertType<IsExact<any, any>>(true); // ok to have any for both
assertType<IsExact<never, never>>(true);
assertType<IsExact<{ prop: string }, { prop: string }>>(true);

assertType<IsExact<string | number | Date, string | number>>(false);
assertType<IsExact<string, string | number>>(false);
assertType<IsExact<string | undefined, string>>(false);
assertType<IsExact<string | undefined, any | string>>(false);