使用 PartialType 扩展的 NestJS DTO 中断验证

NestJS DTO extended with PartialType breaks validation

在 NestJS 中有两个 DTO 鉴于 class ADto & class BDto class ADto extends PartialType(BDto) 类型强制失败。 (参数未从字符串转换为数字,导致 class-validator 抛出错误)。

如果class ADto extends BDto,一切正常。

为什么使用 PartialType 不包括类型强制?

不幸的是,class-validator 库似乎只是 does not support genericsPartial<T> 类型是):

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.