API reference / @evolu/common / Type / optional
Function: optional()
function optional<T>(type): OptionalType<T>;
Defined in: packages/common/src/Type.ts:3658
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),
});
Type Parameters
| Type Parameter |
|---|
T extends AnyType |
Parameters
| Parameter | Type |
|---|---|
type | T |
Returns
OptionalType<T>