API Reference

class-validator

Decorator-based validation for TypeScript classes, with a global validate function and rich constraints.

Official Documentation ↗
CompatibilityThis documentation covers version v0.14. Check the official docs for the latest API surface.

Installation

npmnpm install class-validator

Methods

class-validator attaches metadata via decorators and validates class instances at runtime.

Key Features

  • Decorators for common constraints
  • Nested and array validation
  • Custom validators and messages

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The following points are quoted verbatim from the official documentation (https://github.com/typestack/class-validator). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

Does it work without decorators?
Experiments are experimental; decorators are the supported path. Enable experimentalDecorators and emitDecoratorMetadata in tsconfig.
How do I validate nested objects?
Annotate the property with @ValidateNested() and @Type(() => Child), otherwise the nested instance is not traversed.
How do I strip unknown fields?
Pass whitelist: true and forbidNonWhitelisted: true to validate options so extra properties are rejected or removed.