schemaOf() function
The assembled Zod object schema for a validatable() class, or null when the class contributes no validated fields.
Signature:
export declare function schemaOf(target: Ctor): ZodType | null;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
target |
A class sealed with validatable(). |
Returns:
ZodType | null
A z.object(...) over the class's validated fields, or null if the class was never sealed, declares no validate() fields, or every one of them resolved to no schema.
Remarks
Nested validatable() classes are resolved recursively, so a field validated by another input class produces a nested object schema. A nested class that resolves to null is dropped from the shape rather than reported, which is the same silent outcome described in validate().
null rather than an empty z.object({}) is deliberate — an empty object schema accepts anything, so callers use null to mean there is nothing to check. The cost is that a class with genuinely no rules and a class that forgot validatable() are indistinguishable from the return value alone.
The schema does not reject unknown properties: z.object strips them, so a caller may send fields the class never declared and validation still passes.
Example
const schema = schemaOf(Credentials);
if (schema) {
schema.parse(input); // throws ZodError when input is invalid
}
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.