Issue
I am new to nest.js and have a question about it.
I want to extend more than one Dto to my main dto class, but I know it is not possible to extend more than 2 dto classes. Do you have any idea how to do it ?
Here is my main dto class:
export class CarDto extends PickupLocationDto {
@ApiProperty({ example: 'Aventador', description: 'The car name' })
readonly modelName: string;
}
Recently I am only able to extend it from PickupLocationDto class, but I want to extend one more dto class to this CarDto class.
Any help is appreciated.
Solution
Since I use swagger, using @nestjs/mapped-types package does not show all the variables from intersected dtos. therefore, I use IntersectionType from swagger
import { ApiProperty, IntersectionType } from '@nestjs/swagger';
export class Dto3 extends IntersectionType(
Dto1,
Dto2,
) {}
Answered By - theboyonfire
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.