Complete the code to define a DTO class property with a type.
export class CreateUserDto { username: [1]; }
number or boolean for username type.any defeats the purpose of enforcing a data contract.The username property should be a string to enforce the data contract for user names.
Complete the code to add validation decorator to a DTO property.
import { IsString } from 'class-validator'; export class CreateUserDto { @[1]() username: string; }
@IsNumber() or other decorators that don't match the property type.The @IsString() decorator ensures the username is validated as a string, enforcing the data contract.
Fix the error in the DTO by completing the missing decorator to enforce required property.
import { IsString, [1] } from 'class-validator'; export class CreateUserDto { @IsString() @[1]() username: string; }
@IsOptional() which allows the property to be missing.@IsEmail() or @IsNumber().The @IsNotEmpty() decorator ensures the username is not empty, enforcing the data contract that this field is required.
Fill both blanks to create a DTO property with type and validation decorator.
import { [1] } from 'class-validator'; export class UpdateUserDto { @[2]() email: string; }
@IsString() instead of @IsEmail().@IsBoolean().The email property should be validated with @IsEmail() decorator and import to enforce the email format as part of the data contract.
Fill both blanks to define a DTO with multiple validated properties.
import { [1], [2] } from 'class-validator'; export class RegisterUserDto { @[1]() username: string; @[2]() age: number; }
IsNotEmpty or IsBoolean incorrectly.The username is validated as a string with @IsString(), and age is validated as an integer with @IsInt(). Both decorators are imported accordingly to enforce the data contract.