javascript - 如何在 Nestjs 中扩展多个 dto 类

我是 nest.js 的新手,对此有疑问。

我想将多个 Dto 扩展到我的主 dto 类,但我知道不可能扩展超过 2 个 dto 类(class)。你知道怎么做吗?

这是我的主要 dto 类:

export class CarDto extends PickupLocationDto {
  @ApiProperty({ example: 'Aventador', description: 'The car name' })
  readonly modelName: string;
}

最近我只能从PickupLocationDto 类扩展它,但我想再扩展一个dto 类到这个CarDto 类。

感谢任何帮助。

最佳答案

由于我使用 swagger,使用 @nestjs/mapped-types 包不会显示相交 dto 中的所有变量。因此,我使用 Swagger 的 IntersectionType

import { ApiProperty, IntersectionType } from '@nestjs/swagger';

export class Dto3 extends IntersectionType(
  Dto1,
  Dto2,
) {}

https://stackoverflow.com/questions/65420130/

相关文章:

firebase - Flutter Firestore 离线数据库

r - 如何检查 data.table 各行中的值是否相同

python - 从多列的 value_counts 中排除项目

python - 将 dict 值设置为自身会创建无限副本

amazon-web-services - Amazon RDS 和 VPC 端点连接

javascript - 轻松设置 react redux with next.js (React)

python - , 运算符用在条件语句的右侧时有何作用?

windows - 使 HTML 不适用于 Windows 10 中的 Sphinx 文档

r - 如何使用 dplyr 在 R 中转置数据帧?

python - 从 python 列表创建子列表