我有一个这样的类点:
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
是否可以 ?
你的问题类似于this one https://stackoverflow.com/questions/48217146/typescript-method-decorator/48222970#48222970.
您没有特定的上下文对象实例在装饰器方法内部。参数如下(来自https://www.typescriptlang.org/docs/handbook/decorators.html https://www.typescriptlang.org/docs/handbook/decorators.html):
静态成员的类的构造函数,或实例成员的类的原型.
成员的姓名。
成员的属性描述符。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)