Kit
Type aliases

OptionOrNullable

OptionOrNullable<T> = Option<T> | T | null

A flexible type that allows working with Option values or nullable values.

It defines a looser type that can be used when encoding Options. This allows us to pass null or the nested value directly whilst still supporting the Option type for use-cases that need more type safety.

Type Parameters

Type ParameterDescription
TThe type of the contained value.

Example

Accepting both Option<T> and T | null as input.

function double(value: OptionOrNullable<number>) {
  const option = isOption(value) ? value : wrapNullable(value);
  return isSome(option) ? option.value * 2 : 'No value';
}
 
double(42);       // 84
double(some(21)); // 42
double(none());   // "No value"
double(null);     // "No value"

See

On this page