Questions
17 of 29
1What is a pipe in NestJS and what are its two primary uses?
2How does ValidationPipe work with class-validator and class-transformer in NestJS?
3What is the difference between applying a pipe at the param level vs handler level vs globally in NestJS?
4How do you write a custom pipe for parsing and validating a MongoDB ObjectId param in NestJS?
5What are all the built-in pipes NestJS ships with?
6What is class-transformer and how does it complement class-validator in NestJS?
7How do you write a custom pipe that sanitizes a string input (trim and lowercase) in NestJS?
8How do you write a pipe that uses metatype to skip validation for primitive types the same way ValidationPipe does?
9What are the two ways to register a global pipe in NestJS and what is the difference?
10What are all the significant ValidationPipe options and what does each do in NestJS?
11How do you unit test a custom pipe in NestJS?
12Can a pipe be asynchronous in NestJS and how do you implement one?
13How do you write an async custom validator that checks uniqueness against a database in NestJS?
14How do you validate arrays and conditional fields with class-validator in NestJS?
15How do you use validation groups with class-validator to apply different rules for create vs update operations in NestJS?
16What does @Exclude() and @Expose() do and how do you use them to strip sensitive fields from responses?
17What is the excludeExtraneousValues option in class-transformer and how does it differ from whitelist in ValidationPipe?
18How do you make a custom pipe configurable by accepting constructor options in NestJS?
19How do you customise the error response format produced by ValidationPipe in NestJS?
20How do you handle file upload validation with ParseFilePipe and custom file validators in NestJS?
21What interface must a custom pipe implement and what does the transform() method receive?
22What is the difference between a transformation pipe and a validation pipe in NestJS?
23How do you pass options to a built-in pipe like ParseIntPipe or ParseUUIDPipe in NestJS?
24What is class-validator and how does it integrate with NestJS ValidationPipe?
25What is the @ValidateNested() decorator and when must you pair it with @Type()?
26How do you write a custom class-validator decorator in NestJS?
27What does the @Transform() decorator do in class-transformer and when should you use it?
28How does @Type() interact with discriminated unions and polymorphic DTOs in class-transformer?
29How do you write a pipe that validates and parses a date string from a route parameter in NestJS?
17 / 29

What is the excludeExtraneousValues option in class-transformer and how does it differ from whitelist in ValidationPipe?

Difficulty: 5/10
class-transformer, ValidationPipe, NestJS DTO handling

Both strip unknown properties but they operate at different stages and in opposite directions. ValidationPipe whitelist strips unknown properties from the incoming request body during deserialization. excludeExtraneousValues strips properties without @Expose() from the result during serialization. One filters input, the other filters output.

whitelist vs excludeExtraneousValues comparison
Key differences:
  1. 1

    ValidationPipe whitelist — runs during deserialization (JSON to DTO); strips unknown input.

  2. 2

    excludeExtraneousValues — runs during serialization (class to plain); strips unexposed output.

  3. 3

    whitelist does not require @Expose() on DTO properties — it uses the declared class shape.

  4. 4

    excludeExtraneousValues requires every included property to have @Expose() explicitly.

  5. 5

    Use both together for full control: whitelist on input, excludeExtraneousValues on output.

Scenario Questions

0-2 years experience

  1. 1You have a NestJS POST endpoint that receives a DTO. How would you configure the ValidationPipe so that any extra fields are stripped out, and what role does excludeExtraneousValues play in that process?
  2. 2If you enable excludeExtraneousValues on a plainToInstance call but forget to add @Expose() decorators on the DTO properties, what will the resulting object contain?
  3. 3What happens when a client sends an unexpected field while whitelist:true is enabled but excludeExtraneousValues is false?

2-5 years experience

  1. 1Your team noticed that with whitelist:true some legitimate fields are being dropped. How would you switch to using excludeExtraneousValues to achieve the same effect, and what changes are required in the DTO?
  2. 2During debugging you see validation pass but the service receives an object with extra properties. Which configuration is likely missing, and how would you verify it?
  3. 3Explain the trade‑offs between using whitelist:true versus excludeExtraneousValues:true in terms of performance and code maintainability.

5-8 years experience

  1. 1Design a global NestJS setup that enforces stripping of unknown properties for all incoming requests while keeping validation errors informative. Which combination of ValidationPipe options and class‑transformer settings would you choose, and why?
  2. 2With hundreds of DTOs, requiring @Expose() on every property can be noisy. Discuss the impact of this requirement when using excludeExtraneousValues and propose a strategy to reduce boilerplate without sacrificing security.
  3. 3For a PATCH endpoint you need to ignore missing fields but reject extra ones. How would you configure ValidationPipe and class‑transformer to handle both cases correctly?

8+ years experience

  1. 1Your organization is migrating a legacy monolith to NestJS microservices that previously pruned properties manually. How would you plan a migration to use excludeExtraneousValues globally, and what risks or compatibility concerns would you anticipate?
  2. 2A shared DTO library is used by multiple services with different strictness requirements. How would you design the library so some services can use whitelist while others use excludeExtraneousValues without duplicating DTO definitions?
  3. 3Discuss the long‑term maintenance implications of coupling validation logic to class‑transformer decorators versus keeping validation rules separate, especially when dealing with versioned APIs.

Follow-up Questions

  • Can you show a DTO where excludeExtraneousValues changes the result compared to whitelist?
  • What performance impact might you see if you enable these options globally?
  • How would you keep extra fields from a third‑party payload that you still need downstream?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.