简体   繁体   English

使用 TS 装饰器时未定义 PropertyDescriptor

[英]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.

相关问题 当未定义在联合中时,Ts 无法键入未定义 - Ts failing to type as undefined when undefined is in a union 使用babel装饰器时出现意外令牌@ - Unexpected Token @ when using babel decorator TS 装饰器将 function 定义包装在 try catch 中 - TS decorator to wrap function definition in try catch typeof window == “undefined” 在使用 ts-node 时抛出错误 - typeof window == “undefined” throws an error while using ts-node 使用 tsyringe @injectable 时获得对装饰器错误的实验性支持 - Getting Experimental support for decorator error when using tsyringe @injectable 尝试使用“ts-node-esm”运行应用程序时出现 Typescript import.ts 文件运行时错误 - Typescript import .ts files runtime error when trying to run the application using `ts-node-esm` typescript express 在通过 require('./main.ts') 由 nodeJS 运行时无法导出并显示未定义 - typescript express failed to export and show undefined when running by nodeJS through required require('./main.ts') 使用 ts-node 时通过 fork() 调用子进程 - invoke a child process via fork() when using ts-node 在TypeScript文件中使用node.d.ts时发生编译错误 - Compilation error when using node.d.ts in TypeScript file 使用打字稿时变得不确定 - getting undefined when using typescript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM