# schemaOf() function · @imqueue/validation

Source: https://imqueue.org/api/validation/latest/validation.schemaof/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/validation 1.1.0 — generated reference, not hand-written

The assembled Zod object schema for a [validatable()](https://imqueue.org/api/validation/latest/validation.validatable/) class, or `null` when the class contributes no validated fields.

**Signature:**

```typescript
export declare function schemaOf(target: Ctor): ZodType | null;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| target | [Ctor](https://imqueue.org/api/validation/latest/validation.ctor/) | A class sealed with [validatable()](https://imqueue.org/api/validation/latest/validation.validatable/). |


**Returns:**

ZodType \| null

A `z.object(...)` over the class's validated fields, or `null` if the class was never sealed, declares no [validate()](https://imqueue.org/api/validation/latest/validation.validate/) fields, or every one of them resolved to no schema.

## Remarks

Nested [validatable()](https://imqueue.org/api/validation/latest/validation.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()](https://imqueue.org/api/validation/latest/validation.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()](https://imqueue.org/api/validation/latest/validation.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


```typescript
const schema = schemaOf(Credentials);

if (schema) {
    schema.parse(input); // throws ZodError when input is invalid
}
```

