Objects & Shapes
Deep object validation, strictness policies, composition, and prototype pollution defenses.
Object Strictness Policies
Choose how undeclared keys are handled: • .strip() (Default): Silently removes unrecognized keys. • .strict() / infer.strictObject(): Fails with unrecognized_keys issue. • .passthrough() / infer.passthroughObject(): Preserves unrecognized keys. • .catchall(schema): Validates unrecognized keys against an auxiliary schema.
Schema Definition
const User = infer.object({ id: infer.uuid() });
const StrictUser = User.strict();
const LooseUser = User.passthrough();
const CatchallUser = User.catchall(infer.boolean());Extend, Merge, Pick & Omit
Compose and reuse schemas cleanly:
Schema Definition
const Base = infer.object({ id: infer.uuid(), name: infer.string() });
const Extended = Base.extend({ email: infer.string().email() });
const Merged = Base.merge(infer.object({ role: infer.string() }));
const Picked = Base.pick({ name: true });
const Omitted = Base.omit({ id: true });
const KeysEnum = Base.keyof(); // EnumSchema<["id", "name"]>Deep Partial & Required
Use .partial() to make top-level properties optional, or .deepPartial() to recursively make every nested field optional for PATCH endpoints:
Schema Definition
const OrgSchema = infer.object({
name: infer.string(),
owner: infer.object({
id: infer.uuid(),
handle: infer.string()
})
});
const PatchOrgSchema = OrgSchema.deepPartial();Dynamic Records & Dictionaries
Validate dynamic key-value maps with infer.record(keySchema, valueSchema):
Schema Definition
const ConfigMap = infer.record(
infer.string().min(2),
infer.number()
);