mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-16 20:59:26 +00:00
20 lines
532 B
TypeScript
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
|
|
}
|
|
}
|