У меня два декоратора. Декоратор класса и декоратор метода. Декоратор класса определяет метаданные, к которым я хочу получить доступ в декораторе метода.
ClassDecorator:
function ClassDecorator(topic?: string): ClassDecorator {
return (target) => {
Reflect.defineMetadata('topic', topic, target);
// I've also tried target.prototype instead of target
return target;
};
}
MethodDecorator:
interface methodDecoratorOptions {
cmd: string
}
function MethodDecorator(options: decoratorOptions) {
return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
// HERE IS MY PROBLEM
console.log('metaData is: ', Reflect.getMetadata('topic', target));
}
}
И это определение моего класса:
@ClassDecorator('auth')
export class LoginClass {
@MethodDecorator({
cmd: 'login'
})
myMethod() {
console.log('METHOD CALLED');
}
}
ПРОБЛЕМА:
Следующая строка MethodDecorator возвращает metaData is: undefined
. Почему не определено?
console.log('metaData is: ', Reflect.getMetadata('topic', target));
ВОПРОС:
Как я могу получить доступ к метаданным, определенным ClassDecorator, из MethodDecorator?