【问题标题】:Typescript decorators: how to change the type of a decorated parameter with the decorator?Typescript 装饰器:如何使用装饰器更改装饰参数的类型?
【发布时间】:2022-08-15 21:40:25
【问题描述】:

我试图创建一个以这种方式执行的装饰器:

class foo{
    //stuff
    something(@toNumber() id: string): number{
        return id;
    }
}

我不知道这是否可能。

标签: typescript parameters decorator


【解决方案1】:

您可以使用参数装饰器和方法装饰器来实现这一点。 请参阅此示例:https://www.typescriptlang.org/docs/handbook/decorators.html#parameter-decorators

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-23
    • 2020-06-20
    • 2018-06-08
    • 2015-10-23
    • 2020-01-11
    • 2014-01-14
    • 1970-01-01
    • 2017-11-15
    相关资源
    最近更新 更多