# validate() function · @imqueue/validation

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

Field decorator that records a validator for one class field, sitting beside `@property` on an `@imqueue/rpc` input class.

**Signature:**

```typescript
export declare function validate(validator: Validator): (_value: undefined, context: ClassFieldDecoratorContext) => void;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| validator | [Validator](https://imqueue.org/api/validation/latest/validation.validator/) | A Zod schema, a [validatable()](https://imqueue.org/api/validation/latest/validation.validatable/) class for a nested input object, or `null`/`undefined` to record nothing for this field. |


**Returns:**

(\_value: undefined, context: ClassFieldDecoratorContext) => void

The TC39 field decorator that records `validator` against the field.

## Exceptions

Error if applied to anything other than a class field.

## Remarks

The class itself must also carry [validatable()](https://imqueue.org/api/validation/latest/validation.validatable/), and getting that wrong is worse than it sounds. A field decorated here is buffered until a class decorator claims it, and nothing flushes the buffer when a class body simply ends — so a class that uses [validate()](https://imqueue.org/api/validation/latest/validation.validate/) without [validatable()](https://imqueue.org/api/validation/latest/validation.validatable/) leaves its fields behind for whichever class is sealed next. That class then demands properties it does not declare and rejects input that was perfectly valid, while the class with the actual mistake still validates nothing. The error surfaces on the innocent one, so treat an unexplained missing-property failure as a missing [validatable()](https://imqueue.org/api/validation/latest/validation.validatable/) somewhere above it.

The field name becomes the key in the assembled object schema verbatim, so it has to match the property name the caller sends.

## Example


```typescript
import { z } from 'zod';
import { validatable, validate } from '@imqueue/validation';

@validatable()
class Credentials {
    @validate(z.string().email())
    email!: string;

    @validate(z.string().min(8))
    password!: string;
}
```

