Only validates the given value if it is not null.
null
This is similar to the built-in @IsOptional except that it does not allow undefined. Note that this validator does not work as expected with { each: true } (because it is based on @ValidateIf which does not either).
@IsOptional
undefined
{ each: true }
@ValidateIf
// Ensure the value is a string or null (but not undefined).@Nullable()@IsString()value: string | null Copy
// Ensure the value is a string or null (but not undefined).@Nullable()@IsString()value: string | null
Optional
Generic class-validator options.
Only validates the given value if it is not
null
.This is similar to the built-in
@IsOptional
except that it does not allowundefined
. Note that this validator does not work as expected with{ each: true }
(because it is based on@ValidateIf
which does not either).Example