NestJS · Junior · Question 21 of 75
Why should a DTO be a class rather than a TypeScript interface?
- ✓Correct answer: Interfaces disappear after compilation, so the validation pipe has nothing to inspect at runtime
- 2Nest forbids interfaces
- 3Interfaces can't have optional fields
Explanation
Classes keep their decorators and metadata at runtime, which ValidationPipe and Swagger use.