Files
flashcards-api/src/infrastructure/common/helpers/api-schema.ts
2024-04-12 21:20:28 +02:00

20 lines
532 B
TypeScript

type Constructor<T = object> = new (...args: any[]) => T
type Wrapper<T = object> = { new (): T & any; prototype: T }
type DecoratorOptions = { name: string }
type ApiSchemaDecorator = <T extends Constructor>(
options: DecoratorOptions
) => (constructor: T) => Wrapper<T>
export const ApiSchema: ApiSchemaDecorator = ({ name }) => {
return constructor => {
const wrapper = class extends constructor {}
Object.defineProperty(wrapper, 'name', {
value: name,
writable: false,
})
return wrapper
}
}