lukehaas / RunJS

RunJS is a JavaScript playground for macOS, Windows and Linux. Write code with instant feedback and access to Node.js and browser APIs.
https://runjs.app
2.05k stars 44 forks source link

ts decorator seems not working in class #574

Open jakecodev opened 1 year ago

jakecodev commented 1 year ago
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 commented 1 year ago

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

jakecodev commented 1 year ago

Thank you, that makes total sense. @lukehaas.

jakecodev commented 1 year ago

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 commented 1 year ago

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