79203337

Date: 2024-11-19 12:08:32
Score: 1
Natty:
Report link

In the second version, the following changes ensure proper transformation:

transformOptions: { enableImplicitConversion: true }

This option allows ValidationPipe to implicitly convert types based on the destination type in the DTO or class. In this case, it converts strings to numbers or arrays of numbers without needing explicit @Type decorators. Documentation: ValidationPipe Options - transformOptions

Decorators like @Type(() => Number):

This explicitly tells class-transformer how to convert incoming query parameters to the intended type, making sure that arrays like ['1', '2'] is converted to [1, 2]. Documentation: @Type Decorator - class-transformer

But the first example by default the enableImplicitConversion is set to false and this prevent the convertion of the param criteria

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Type
  • Low reputation (1):
Posted by: Saeed Ghofrani