Skip to content

optional

Wraps an undefined/defined value in an Either, useful for propagating optional fields.

Interactive example

Syntax

typescript
function optional<
	const GenericInput extends unknown = undefined
>(
  input: GenericInput
): GenericInput extends undefined
  ? EitherOptionalEmpty
  : EitherOptionalFilled<GenericInput>;

Parameters

  • input: Can be undefined or a concrete value.

Return value

  • EitherOptionalFilled if the value is defined.
  • EitherOptionalEmpty otherwise.

See also

Released under the MIT license.