Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 655 Bytes

File metadata and controls

43 lines (31 loc) · 655 Bytes

typelab / assertions / IsNullable

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

Checks if a given type T has null type.

Type Parameters

Type Parameter Description

T

The type to be checked.

Returns

true if T has null type, false otherwise.

Example

type Valid = IsNullable<string | null>; // true
type Invalid = IsNullable<string>; // false