API Reference / @evolu/common / Type / nullishOr

Function: nullishOr()

function nullishOr<T>(type): UnionType<[Type<"Undefined", undefined, undefined, UndefinedError, undefined, UndefinedError>, Type<"Null", null, null, NullError, null, NullError>, T]>;

Defined in: packages/common/src/Type.ts:3125

union(undefined, null, T) Type.

Learn more: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing

Example

const NullishOrString = nullishOr(String);
NullishOrString.from("test"); // ok("test")
NullishOrString.from(null); // ok(null)
NullishOrString.from(undefined); // ok()
NullishOrString.from(42); // err(...)

Type Parameters

Type Parameter
T extends AnyType

Parameters

ParameterType
typeT

Returns

UnionType<[Type<"Undefined", undefined, undefined, UndefinedError, undefined, UndefinedError>, Type<"Null", null, null, NullError, null, NullError>, T]>

Was this page helpful?