Skip to main content

Introduction

Class-validator is a TypeScript library that uses decorators to validate classes and their properties. It provides a declarative way to validate data using annotations directly on class properties.

Inversify Validation's Class Validation Pipe integrates seamlessly with class-validator, allowing you to validate incoming HTTP parameters (e.g., request body) using decorated classes in your controllers.

Install dependencies

In order to use the package, install it along with the required peer dependencies:

npm install class-validator class-transformer @inversifyjs/class-validation

TypeScript Configuration

Class-validator requires specific TypeScript compiler options to function properly. Make sure your tsconfig.json includes:

{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}