0
0
NestJSframework~5 mins

class-validator decorators in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of @IsString() decorator in class-validator?
The @IsString() decorator checks if the value of a property is a string. It helps ensure the data type is correct before processing.
Click to reveal answer
beginner
How does @IsNotEmpty() decorator help in validation?
The @IsNotEmpty() decorator ensures that a property is not empty. It rejects empty strings, null, or undefined values to guarantee required data is present.
Click to reveal answer
beginner
What does @IsEmail() decorator validate?
The @IsEmail() decorator checks if the property contains a valid email address format. It helps catch invalid emails early.
Click to reveal answer
intermediate
Explain the use of @MinLength(5) decorator.
The @MinLength(5) decorator ensures the string property has at least 5 characters. It helps enforce minimum length rules like passwords or usernames.
Click to reveal answer
intermediate
What is the role of @ValidateNested() decorator?
The @ValidateNested() decorator validates nested objects inside a class. It tells class-validator to check the inner object's decorators too.
Click to reveal answer
Which decorator checks if a property is a number?
A@IsBoolean()
B@IsString()
C@IsNumber()
D@IsEmail()
What does @IsOptional() do in class-validator?
AMakes a property required
BSkips validation if the property is missing
CChecks if a property is a string
DValidates nested objects
Which decorator would you use to ensure a string is not empty?
A@IsNotEmpty()
B@IsEmail()
C@MinLength(1)
D@IsString()
How do you validate that a property is an array?
A@IsArray()
B@IsObject()
C@IsString()
D@IsNumber()
What is the use of @ValidateNested()?
AMakes a property optional
BChecks if a property is a number
CEnsures a string is an email
DValidates nested objects inside a class
Describe how you would use class-validator decorators to ensure a user signup form has a valid email, a password with minimum length 8, and an optional nickname.
Think about which decorators check format, length, and optional fields.
You got /3 concepts.
    Explain why @ValidateNested() is important when validating objects that contain other objects.
    Consider how validation works on nested data structures.
    You got /3 concepts.