@IsOptional() + @NotEquals(null) not working
See original GitHub issueI want to validate displayName with optional and not equal null but it not working. it does not validate @NotEquals(null)
.
export class UpdateDto implements Partial<UserEntity> {
@ApiProperty()
@IsOptional()
@NotEquals(null)
displayName?: string;
}
this case is pass input:
{
displayName: null
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Class Validate Not Null - StackBlitz
IsOptional,. NotEquals. } from "class-validator";. import "reflect-metadata";. /**. * test for https://github.com/typestack/. class-validator/issues/579.
Read more >class validator - How to allow null, but forbid undefined?
It turns out that this is possible by using conditional validation ValidateIf : class DbRow { @IsNumber() id!: number; @IsNumber() ...
Read more >class-validator - npm
Decorator-based property validation for classes.. Latest version: 0.14.0, last published: 16 days ago. Start using class-validator in your ...
Read more >Validation Chain API - express-validator
.bail(). Returns: the current validation chain instance. Stops running validations if any of the previous ones have failed.
Read more >How to Check If Two Variant Values Are Equal (or Not) in VBA
When are two identical values not equal? ... And that means we spend a lot of time working with Nulls. ... The Notes...
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
Recommended I suggest, that you remove
@NotEquals(null)
and setskipMissingProperties
totrue
in the validation optionssee this Stackblitz example
Alternative
When you want to use the default validation options, you can use
ValidateIf
to make it work:This will pass the validation when
displayName
isundefined
or a string, but fail fornull
.see this Stackblitz example
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.