API reference@evolu/commonType › undefinedOr

function undefinedOr<ValueType>(
  type: ValidateUnionTypeMember<ValueType>,
): UnionType<readonly [ValueType, LiteralType<undefined>]>;

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

Union Type containing the supplied Type and undefined.

This does not make an object property optional. It changes only the values accepted when the property is present.

Example

import { assertOk, String, undefinedOr } from "@evolu/common";

const StringOrUndefined = undefinedOr(String);

assertOk(StringOrUndefined.fromUnknown(undefined), undefined);