egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
8.46k stars 209 forks source link

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

Open paulsmithkc opened 2 months ago

paulsmithkc commented 2 months ago

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

Fund with Polar