Skip to content

Nullable

Adds null to a type (T | null).

Useful as a shorthand when explicit nullability should be expressed in function signatures or generic constraints.

Available since v3.0.0

import type { Nullable } from '@helpers4/type';
// or, from the all-in-one package (same code, one install):
import type { Nullable } from 'helpers4/type';
type Nullable<T> = T | null
type MaybeUser = Nullable<User>; // User | null

function findUser(id: string): Nullable<User> { ... }

View source on GitHub