In my project, I am dealing with multiple endpoints that provide responses along with pagination details. My goal is to have a single parent type for the pagination and be able to use different data types for the data
parameter.
I attempted the following approach, but encountered a problem where the statement within @Type
resulted in an error message stating
'T' only refers to a type, but is being used as a value here.
, indicating that it requires a value or class rather than a type:
export class PaginatedResponseDto<T> {
@Expose()
@ApiProperty()
skip: number;
@Expose()
@ApiProperty()
take: number;
@Expose()
@ApiProperty()
count: number;
@Expose()
@ApiProperty()
@Type(() => T[]) // <- this is not working, because I cannot use `T` here
data: T[];
constructor(data: any) {
Object.assign(this, data);
}
}
During my research, I came across a solution (reference link provided) that seemed promising, although it led to double transformation of the response, causing complications with date values.
I am curious if there exists an alternative method to achieve this objective, instead of creating multiple PaginatedResponseDto
classes?