我是 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,
) {}
关于javascript - 如何在 Nestjs 中扩展多个 dto 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65420130/