object
Use this schema to validate objects from a shape of nested schemas.
import {object, string, number} from '@livon/schema';
const User = object({
name: 'User',
shape: {
id: string(),
name: string().min(2),
age: number().int().min(0),
},
});
const value = User.parse({
id: 'u-1',
name: 'Alice',
age: 30,
});
object fields can use any value schema from this section.
API schemas (api) are not valid as object field schemas.
Parameters
name(string, required): object schema name.shape(Record<string, Schema>, required): field schema map.doc(SchemaDoc, optional): schema metadata attached to AST/doc output.
Chain API
- No schema-specific chain methods.
- Shared methods on current type
T = Infer<object.shape>:optional(): Schema<T | undefined>,nullable(): Schema<T | null>,describe(doc: SchemaDoc): Schema<T>,refine(input): Schema<T>,before(hook): Schema<T>,after<U>(hook): Schema<U>,and<U>(other: Schema<U>, options?: {name?: string}): Schema<T & U>.