Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 766 Bytes

File metadata and controls

44 lines (32 loc) · 766 Bytes

typelab / assertions / IsNullish

type IsNullish<T> = IsAny<T> extends true ? false : IsNever<T> extends true ? false : IsUnknown<T> extends true ? false : [undefined] extends [T] ? true : [null] extends [T] ? true : false;

Checks if a given type T has null | undefined type.

Type Parameters

Type Parameter Description

T

The type to be checked.

Returns

true if T has null | undefined type, false otherwise.

Example

type Valid1 = IsNullish<string | null>; // true
type Valid2 = IsNullish<string | undefined>; // true
type Invalid = IsNullish<string>; // false