Recall & Review
beginner
What is the main purpose of the
class-transformer library in NestJS?It helps convert plain JavaScript objects into class instances and vice versa, making it easier to work with typed data and apply transformations or validations.Click to reveal answer
beginner
How do you use
@Expose() decorator in class-transformer?The <code>@Expose()</code> decorator marks a class property to be included when transforming an object to plain or class instance, allowing control over which properties are visible.Click to reveal answer
beginner
What does the
plainToInstance() function do?It converts a plain JavaScript object into an instance of a specified class, applying any decorators like
@Type() or @Expose() during the transformation.Click to reveal answer
intermediate
Why would you use
@Type(() => SomeClass) in a DTO class?To tell
class-transformer how to transform nested objects or arrays into instances of the specified class, ensuring proper typing and transformation of nested data.Click to reveal answer
intermediate
What is the effect of using
excludeExtraneousValues: true option in transformation?It removes any properties from the plain object that do not have
@Expose() decorator in the class, helping to keep only intended data and improve security.Click to reveal answer
Which function converts a plain object to a class instance in
class-transformer?✗ Incorrect
The
plainToInstance() function converts plain objects to class instances.What does the
@Expose() decorator do?✗ Incorrect
@Expose() marks properties to be included when transforming objects.How do you specify the type of a nested object for transformation?
✗ Incorrect
Use
@Type(() => ClassName) to specify nested object types.What happens if you set
excludeExtraneousValues: true during transformation?✗ Incorrect
Only properties decorated with
@Expose() are included when excludeExtraneousValues is true.Which decorator is NOT part of
class-transformer?✗ Incorrect
@Validate() is from class-validator, not class-transformer.Explain how you would use
class-transformer to convert a plain JSON object into a typed class instance with nested objects in NestJS.Think about how to prepare your classes and call the right function.
You got /4 concepts.
Describe the benefits of using
excludeExtraneousValues: true option in data transformation.Consider what happens to properties without @Expose() when this option is enabled.
You got /4 concepts.