API Reference / @evolu/common / Type / partial
Function: partial()
function partial<Props>(props): ObjectType<{ [K in string | number | symbol]: OptionalType<Props[K]> }>;
Defined in: packages/common/src/Type.ts:3588
Creates a partial object type where all properties are optional.
This is useful when you want to validate an object in which none of the keys are required, but if they are present they must conform to their corresponding Types.
Example
const PartialUser = partial({
name: NonEmptyString,
age: PositiveNumber,
});
// Valid: an empty object is accepted
PartialUser.from({});
// Valid: when provided, the properties must validate correctly
PartialUser.from({ name: "Alice" });
// Invalid: if a property is present but fails validation it returns an error
PartialUser.from({ age: -5 });
Type Parameters
Type Parameter |
---|
Props extends Record <string , AnyType > |
Parameters
Parameter | Type |
---|---|
props | Props |
Returns
ObjectType
<{ [K in string | number | symbol]: OptionalType<Props[K]> }>