как получить доступ к параметрам декоратора класса из метода декоратора - PullRequest
0 голосов
/ 17 февраля 2019

Я хотел бы использовать информацию, передаваемую декоратору класса из метода декоратора того же класса.Вот как выглядит (фиктивный) класс:

@classDecorator({
  something: 'very interesting'
})
class MyClass{
  @methodDecorator({
    pure: false
  })
  someMethod() {
    ...
  }
}

Теперь меня интересует использование параметра, переданного classDecorator ({something: very interesting'}) из метода methodDecorator.

Iнадеялся, что смогу использовать Reflect API, но безрезультатно:

function classDecorator(info) {
  // classDecorator parameter available here as 'info'

  return function(target, propertyKey, descriptor) {
    return descriptor
  }
}

function methodDecorator(config) {
  // propertyDecorator parameter availabe here as 'config'
  return function(target, propertyKey, descriptor) {

    // I thought I could access the class' decorator params with the reflect api
    Reflect.getMetadata('custom:annotation', target)
    Reflect.getMetadata('design:type', target)
    Reflect.getMetadata('design:paramtypes', target)
    // but all of the above are undefined

    return descriptor
  }

}

Возможно ли получить доступ к параметрам classDecorator из метода methodDecorator в том же классе?

...