NestJS DTO extended with PartialType breaks validation

3.1k views Asked by At

With two DTO in NestJS given class ADto & class BDto class ADto extends PartialType(BDto) type-coercion fails. (Params are not converted to number from string, resulting in class-validator throwing an error).

If class ADto extends BDto, all works.

Why does using PartialType not include type-coercion?

1

There are 1 answers

1
eol On BEST ANSWER

Unfortunately it seems that the class-validator library simply does not support generics (which Partial<T> types are):

Generics are not supported because TypeScript does not have good reflection abilities yet. Once TypeScript team provide us better runtime type reflection tools, generics will be implemented.