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

tsup ignores useDefineForClassFields, and always generates definitions for class fields #1104

Open
paulsmithkc opened this issue Apr 5, 2024 · 0 comments

Comments

@paulsmithkc
Copy link

paulsmithkc commented Apr 5, 2024

When compiling with the typescript compiler (tsc), how class fields are transformed depends on the value of useDefineForClassFields, but the tsup is currently ignoring this setting.

This causes problems with field decorators.

Original typescript code:

export class Foo {
  @customDecorator()
  public readonly value!: string;
}

Result of tsc with useDefineForClassFields = false

class Foo {
}

Result of tsc with useDefineForClassFields = true

class Foo {
    constructor() {
        Object.defineProperty(this, "value", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
    }
}

Result of tsup regardless of useDefineForClassFields value

var Foo = class {
  constructor() {
    __publicField(this, "value");
  }
}

The issue here is that the __publicField() logic which is being added, prevents processing of field decorators.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@paulsmithkc paulsmithkc changed the title tsup ignores useDefineForClassFields always generates definitions for class class fields tsup ignores useDefineForClassFields, and always generates definitions for class class fields Apr 5, 2024
@paulsmithkc paulsmithkc changed the title tsup ignores useDefineForClassFields, and always generates definitions for class class fields tsup ignores useDefineForClassFields, and always generates definitions for class fields Apr 5, 2024
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

1 participant