optionalOr
optionalOr is defaultTo with the source Spot wrapped in optional. It uses the fallback when the source is missing or its value is null or undefined.
// without optionalOrconst userName = defaultTo(optional(fetchUser.result.name), "Guest")// with optionalOrconst userName = optionalOr(fetchUser.result.name, "Guest")
// without optionalOrconst userName = defaultTo(optional(fetchUser.result.name), defaultName.value)// with optionalOrconst userName = optionalOr(fetchUser.result.name, defaultName.value)Arguments
Section titled “Arguments”spot: Spot<T>— the source Spot, treated as optional.fallback: P | Spot<P>— a fallback value, or a Spot that provides it.
Returns
Section titled “Returns”Spot<NonNullable<T> | P> — the source value when available and not null or undefined; otherwise, the fallback value.