Skip to content

nullable

Allows null while applying a strict parser when the value is present. DDataParser.nullable(inner) returns null or the output of inner.

Interactive example

Parameters

  • inner: parser used when the value is not null.
  • coalescingValue: optional, replaces null with a default value and narrows the output type.
  • checkers: checkerRefine or other helpers applied on Output<inner> | null.
  • errorMessage: message for inputs that are neither null nor valid for inner.

Return value

A DataParserNullable. schema.parse(data) returns DEither.success<Output | null> or DEither.error<DataParserError>. Checkers let you, for example, restrict dates to a period even when they are optional.

Other examples

Extended mode

See also

Released under the MIT license.