lukehaas/RunJS

ts decorator seems not working in class

fullstackneo opened this issue · 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

@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?

Thank you, that makes total sense. @lukehaas.

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

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