NestJS · Junior · Question 21 of 75

Why should a DTO be a class rather than a TypeScript interface?

Explanation

Classes keep their decorators and metadata at runtime, which ValidationPipe and Swagger use.

Further reading

Problem with a question

NestJS · Junior · question 21

Test yourself

Take the NestJS · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz