Looking for a way to create a class decorator that ensures the target class extends another class.
Here's a hypothetical example:
@CustomDecorator
class MyClass extends BaseClass
{
}
The goal is for @CustomDecorator
to require the target class to extend BaseClass
.
I've experimented with various approaches, but haven't had any success. I thought it would be as simple as this:
export function CustomDecorator(options: DecoratorOptions)
{
return <T extends BaseClass>(target: T): T => {
console.log(target);
return target;
};
}
Therefore, if MyClass
does NOT extend BaseClass
, I want TypeScript compilation to fail.
Any assistance on this matter would be highly appreciated!