-
Notifications
You must be signed in to change notification settings - Fork 800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inheriting Validation decorators #633
Comments
I'm seeing the same. It does not appear to behave as documented. @shymanel The empty array output from your example indicates no validation errors. |
@cduff yep, thanks, I figured it out. I though there should be an error, since |
FYI, since commenting on this issue earlier I've been using class-validator more and have come to realise that not having it inherit decorators is useful sometimes. For example, I can have code like:
For a So now I'm wondering if the decorators are not inheriting by design? |
I encounter the same issue described by @shymanel. https://github.com/typestack/class-validator#inheriting-validation-decorators I would like to update to version 0.12.2, but this seems to be broken now and affects a lot of unit tests in my project. |
There is now a PR for this |
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. |
While we are waiting for merge, you can make your own decorator and call it in child class.
|
Please, please, please - someone pick this up urgently. This is a clear regression from V11 and we are on V13 already without this being fixed. |
Just FYI. It only makes sense to inherit if the decorators don't conflict with each other. |
hey bro, how did you fix this :( |
The documentation says inheritance should work: #633. But, it doesn't for me, I get:
I tried the solution from #633 (comment) and got the same error. This is from Within NestJS I've found a solution/hack that does the inheritance: import { OmitType } from "@nestjs/swagger";
class ChildClass extends OmitType(BaseClass, []) {
@IsUppercase()
someProperty: string;
} For now I can use the type helpers (pick/omit) from Edit: clarified that I've read the docs. |
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
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
The text was updated successfully, but these errors were encountered: