Type Alias Has<T, U>

Has<T, U>: IsAny<T> extends true
    ? true
    : IsAny<U> extends true
        ? false
        : Extract<T, U> extends never
            ? false
            : true

Checks if type T has the specified type U.

Type Parameters

  • T

    The type to check if it has the specified type U.

  • U

    The type to check if it is in the type T.

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

assertType<Has<string | number, string>>(true);
assertType<Has<any, number>>(true);

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