Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts decorator seems not working in class #574

Open
fullstackneo opened this issue Aug 13, 2023 · 4 comments
Open

ts decorator seems not working in class #574

fullstackneo opened this issue Aug 13, 2023 · 4 comments

Comments

@fullstackneo
Copy link

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

@lukehaas
Copy link
Owner

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

@fullstackneo
Copy link
Author

fullstackneo commented Aug 13, 2023

Thank you, that makes total sense. @lukehaas.

@fullstackneo
Copy link
Author

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

@lukehaas
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants