Being relatively new to TypeScript, I'm looking to initialize an object for response data as shown below:
const auth = new ResponseData<Clazz>();
I have a mixin called BaseResponseHelper
as follows:
type Constructor<T = object> = new (...args: any[]) => T;
export function BaseResponseHelper<TBase extends Constructor>(Base: TBase, options?: ApiPropertyOptions | undefined) {
class ResponseDTO {
@ApiProperty({ description: 'API execution error code', example: '0000' })
@IsString()
error_code!: string;
@ApiProperty({
description: 'Error code content',
example: '[XXXX]Successfully executed',
})
@IsString()
error_desc!: string;
@ApiProperty({
description: 'API execution status',
example: true,
})
@IsBoolean()
success!: boolean;
@ApiProperty({
isArray: true,
type: () => Base,
example: () => Base,
description: 'Structure of returned data',
...options,
})
@Type(() => Base)
@ValidateNested({ each: true })
data_list!: Array<InstanceType<TBase>>;
}
return mixin(ResponseDTO);
}
I tried implementing a class like this but encountered issues:
export class ResponseData<T> extends BaseResponseHelper(T) {}
Any suggestions on how to pass generic types in the ResponseData.ts file?
Appreciate your help!
export class ResponseData<T> extends BaseResponseHelper(T) {}