API reference › @evolu/common › Type › optional
function optional<T>(type: T): OptionalType<T>;
Defined in: packages/common/src/Type.ts:4354
Optional Type.
Marks a Type as optional, meaning:
- If the value is present, it must match the given
Type. - If the value is absent, it is not included in the final object.
This is different from undefinedOr, which allows explicit undefined
but still requires the key to exist.
Example:
const Todo = object({
id: TodoId,
title: NonEmptyString1000,
isCompleted: optional(SqliteBoolean),
});