IsNullable

import { IsNullable } from "jsr:@ende/testing/types";

type alias

type IsNullable<T> = Extract<T, null | undefined> extends never ? false : true

Checks if type T is possibly null or undefined.

Example: Usage

import { assertType, IsNullable } from "@ende/testing/types";

assertType<IsNullable<string | null>>(true);
assertType<IsNullable<string | undefined>>(true);
assertType<IsNullable<null | undefined>>(true);

assertType<IsNullable<string>>(false);
assertType<IsNullable<any>>(false);
assertType<IsNullable<never>>(false);

Source