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
  ? EitherNullishEmpty<GenericInput>
  : EitherNullishFilled<GenericInput>;

Parameters

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

Return value

  • EitherNullishFilled when the value exists.
  • EitherNullishEmpty when the value is null or undefined.

See also

Released under the MIT license.