Inheriting Validation decorators

Author: ghostCreated Jun 11, 2020Updated Mar 23, 2026
Labelstype: fix

Description

From the docs:

If a property is redefined in the descendant class decorators will be applied on it both from that and the base class.

I'm not sure it works as it should.

Reproduction

typescript
import { MinLength, IsUppercase } from "class-validator";
import { validate } from "class-validator";

class BaseClass {
    @MinLength(10)
    someProperty: string;
}

class ChildClass extends BaseClass {
    @IsUppercase()
    someProperty: string;
}

const someObj = new ChildClass();
someObj.someProperty = 'HELLO';

validate(someObj).then(result => {
    console.log(result);
});

// the output is empty array []

From what I'm reading in docs, I thought @MinLength(10) is used alongside @IsUppercase(), but I don't see it. Moreover, I'm not sure what empty array means.

Environment

  • nodejs: v12.17.0
  • typescript: 3.9.5

Source: typestack/class-validator