Open
Description
I have this class
class A {
@IsString()
@MaxLength(99)
prop1: string
@IsBoolean()
prop2: boolean
}
I want it to be:
- string.
- required (if prop2 is true).
- optional if prop2 is false.
In class-validator, there's is the @ValidateIf()
class A {
@IsString()
@MaxLength(99)
@ValidateIf((obj) => obj.prop2)
prop1: string
@IsBoolean()
prop2: boolean
}
It's true that ValidateIf()
will make prop1 optional when prop2 is false
. But it will disable my checking for @MaxLength()
and for @IsString()
. Now you can pass a number! that's not what I want. I just want it to be optional.
I was thinking, Isn't there a way to say @IsRequiredIf()
or @IsOptionalIf()
instead of saying @ValidateIf()
?