我有一个类似的点:
class Point {
@test('admin') x: number = 6
y: number = 5
}
使用测试装饰器:
function test(myValue: string) {
function t(target: Object, propertyKey: string, descriptor:
TypedPropertyDescriptor<any>) {
//want to test y value > x value
}
return <any>t
}
在我的测试中,我想检查y值的例子,如果x&lt; ÿ
有可能吗?
答案 0 :(得分:2)
您的问题与this one类似。
在装饰器方法中没有特定对象实例的上下文。参数如下(来自https://www.typescriptlang.org/docs/handbook/decorators.html):
静态成员的类的构造函数,或实例成员的类的原型。
会员的名字。
会员的属性描述符。