Skip to content

nullish ​

Transforms a potentially null/undefined value into an Either. Allows propagating presence/absence in a type-safe way.

Interactive example ​

Syntax ​

typescript
function nullish<const GenericInput extends unknown = undefined>(
  input: GenericInput
): GenericInput extends NullishValue
  ? NullishEmpty<GenericInput>
  : NullishFilled<GenericInput>;

Parameters ​

  • input: Value to wrap (null, undefined, or any other value).

Return value ​

  • NullishFilled when the value exists.
  • NullishEmpty when the value is null or undefined.

See also ​

Released under the MIT license.