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?
✗ Incorrect
The @IsNumber() decorator validates that the property is a number.
What does @IsOptional() do in class-validator?
✗ Incorrect
The @IsOptional() decorator skips validation if the property is not present.
Which decorator would you use to ensure a string is not empty?
✗ Incorrect
@IsNotEmpty() ensures the property is not empty, rejecting empty strings.
How do you validate that a property is an array?
✗ Incorrect
@IsArray() checks if the property is an array.
What is the use of @ValidateNested()?
✗ Incorrect
@ValidateNested() tells class-validator to validate nested object properties.
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.