Inheriting Validation decorators
See original GitHub issueDescription
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
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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:9 (1 by maintainers)
Top Results From Across the Web
How can I make my class decorator only run on the outermost ...
I'm using class-validator decorators to validate data classes that involve data coming from outside of my application at runtime.
Read more >Validation decorator - pydantic
The validate_arguments decorator allows the arguments passed to a function to be parsed and validated using the function's annotations before the function is ......
Read more >Validation - Next.js API Decorators
The options you can pass into ValidationPipe are inherited from class-validator with an additional transformerOptions property, which inherits class-transformer ...
Read more >Validation | NestJS - A progressive Node.js framework
In addition to these, all class-validator options (inherited from the ... (returned) object of any properties that do not use any validation decorators....
Read more >How to Validate Your Data with Custom Validators of Pydantic ...
To create a custom validator, we need to import the validator function which works like a decorator and decorates some methods of the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Any update on this? I got hit by it again today. It’s quite confusing at the moment as some decorators are inherited (e.g. @IsOptional) and others aren’t.
There is now a PR for this