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
  ? OptionalEmpty
  : OptionalFilled<GenericInput>;

Parameters ​

  • input: Can be undefined or a concrete value.

Return value ​

  • OptionalFilled if the value is defined.
  • OptionalEmpty otherwise.

See also ​

Released under the MIT license.