RunJS icon indicating copy to clipboard operation
RunJS copied to clipboard

ts decorator seems not working in class

Open jakecodev opened this issue 2 years ago • 4 comments

const decor: PropertyDecorator = (
  target: Object,
  key: string | symbol,
) => {
  console.log(target, key)
}

class A {
  @decor
  public name: string | undefined
}

const obj = new A()

Expected:

{} name

Real Result:

undefined {
  kind: 'field',
  name: 'name',
  static: false,
  private: false,
  access: { get: ƒ get(), set: ƒ set() }
}

I also tried MethodDecorator, it seem the target and descriptor are all undefined. And this is my setting. Thank you very much.

image

jakecodev avatar Aug 13 '23 07:08 jakecodev

@fullstackneo plugin-proposal-decorators is for JavaScript decorators, not TypeScript decorators. I'm not sure if they work the same way but could this explain the difference between your expectation and actual output?

lukehaas avatar Aug 13 '23 16:08 lukehaas

Thank you, that makes total sense. @lukehaas.

jakecodev avatar Aug 13 '23 19:08 jakecodev

Thank you very much for your kind help. Is there any way to make TS decorators run correctly in the app? @lukehaas Thank you.

jakecodev avatar Aug 16 '23 19:08 jakecodev

@fullstackneo not in the current release, but I'll see if I can add support for it in the next version.

lukehaas avatar Aug 17 '23 07:08 lukehaas