Commit 875e2517 authored by nanahira's avatar nanahira

new

parent 2043ecdc
Pipeline #14513 passed with stages
in 2 minutes and 15 seconds
......@@ -29,13 +29,24 @@ export class BlankReturnMessageDto implements BlankReturnMessage {
}
}
export class ReturnMessageDto<T>
extends BlankReturnMessageDto
implements ReturnMessage<T> {
@ApiProperty({ description: '返回内容' })
data?: T;
constructor(statusCode: number, message?: string, data?: T) {
super(statusCode, message);
this.data = data;
}
export type AnyClass = new (...args: any[]) => any;
export type ClassType<T> = new (...args: any[]) => T;
export type ClassOrArray = AnyClass | [AnyClass];
export type TypeFromClass<T extends AnyClass> = T extends new (
...args: any[]
) => infer U
? U
: never;
export type ParseType<T> = T extends [ClassType<infer U>] ? U : ClassType<T>;
export function ReturnMessageDto<T extends ClassOrArray>(type: T) {
const cl = class SpecificReturnMessage extends BlankReturnMessageDto {
data?: ParseType<T>;
constructor(statusCode: number, message?: string, data?: ParseType<T>) {
super(statusCode, message);
this.data = data;
}
};
ApiProperty({ description: '返回数据', type })(cl.prototype, 'data');
return cl;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment