defaultTo
2 overloads
defaultTo<T>(fallback: T[], primitive: ArrayTypedPrimitive<T>): ArrayTypedPrimitive<T>Wraps a primitive so that missing or empty-string inputs produce fallback instead.
An array primitive keeps its string | string[] calling convention through the wrapper
(an array input falls through to the wrapped parser untouched).
fallback T[]
primitive ArrayTypedPrimitive<T>
returns ArrayTypedPrimitive<T>
Example:
const countOrZero = defaultTo(0, int.min(0));const idsOrNone = defaultTo([], array(int));defaultTo<T>(fallback: T, primitive: TypedPrimitive<T>): TypedPrimitive<T>Wraps a primitive so that missing or empty-string inputs produce fallback instead.
An array primitive keeps its string | string[] calling convention through the wrapper
(an array input falls through to the wrapped parser untouched).
fallback T
primitive TypedPrimitive<T>
returns TypedPrimitive<T>
Example:
const countOrZero = defaultTo(0, int.min(0));const idsOrNone = defaultTo([], array(int));Learn: Primitives and builders