打字稿中的装饰器通信

decorators communication in typescript

我正在使用打字稿制作一个 nodejs 应用程序,这是我的 class 的样子

@lib.decorators.routesRegister().version('v1')
export class mediaController extends lib.baseClasses.apiControllerAsyncBase().apiControllerAsync {


@lib.decorators.dtoRegister().dto(dto.media)
@lib.decorators.routesRegister().register({ url: "", cache:"10000" })
public async getMedia() {

    let param = {
        where: {
            status_id: {
                $ne: enums.status.DELETED
            }
        }
    }
    return this.ok(await lib.factory.createMySQLSequelizeAsyncObj('media_types').findAllAsync(param));

  }
}

我的问题是,当函数装饰器 'register' 被调用时,我需要在 class 装饰器 'version' 中传递的值,我怎样才能达到相同的效果,请帮我解决问题

my problem is, that when the function decorator 'register' is getting called i need the value which is being passed in the class decorator 'version'

取决于 routesRegister() 的实施。以下最有可能起作用:

const routesRegister = lib.decorators.routesRegister().version('v1');
@routesRegister
export class mediaController extends lib.baseClasses.apiControllerAsyncBase().apiControllerAsync {


@lib.decorators.dtoRegister().dto(dto.media)
@routesRegister.register({ url: "", cache:"10000" })
public async getMedia() {

所以添加到 basarat 的答案是我是如何做到的

const routeRegister = lib.decorators.routesRegister().version('v1');


export class mediaController extends  lib.baseClasses.apiControllerAsyncBase().apiControllerAsync {


@lib.decorators.dtoRegister().dto(dto.media)
@routeRegister({ url: "", cache: "10000" })
public async getMedia() {

    let param = {
        where: {
            status_id: {
                $ne: enums.status.DELETED
            }
        }
    }
    return this.ok(await lib.factory.createMySQLSequelizeAsyncObj('media_types').findAllAsync(param));

    }

}

装饰器看起来像

   export function version(version) {

      return (route?: Object)=> {

         return (target: any, key, value) => {
             //decorator definition here
      }
    }  
 }