[英]PropertyDescriptor undefined when using TS decorator
TS Decorator TS 装饰器
function exampleDeco(): any {
return function (
target: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {
console.log(descriptor?.value, "descriptor");
return descriptor;
};
}
Result:结果:
undefined descriptor
Function used on使用的函数
@exampleDeco()
public exampleFn = (
) => { console.log('function') }
I don't know why it's logging undefined in the decorator.我不知道为什么它在装饰器中记录未定义。
It was due to the use of TS decorator on the arrow function ()=>{}
.这是由于在箭头函数
()=>{}
上使用了 TS 装饰器。 It will work just fine if you use it on a normal JS function.如果您在普通的 JS 函数上使用它,它会工作得很好。 Not sure why it is behaving like this though.
不知道为什么它会这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.