microsoft / tslib

Runtime library for TypeScript helpers.
BSD Zero Clause License
1.26k stars 130 forks source link

Regression in tslib@2.5.1 when using private fields i.c.m. with ESM #207

Closed nicojs closed 1 year ago

nicojs commented 1 year ago

Input:

export class File {
  #relativePath: string = "";
  constructor(name: string) {
    this.#relativePath = name;
  }

  get relativePath() {
    return this.#relativePath;
  }
}

With settings:

{
  "compilerOptions": {
    "module": "Node16",
    "target": "es2022",
    "moduleResolution": "Node16",
    "esModuleInterop": true,
    "outDir": "dist",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "importHelpers": true,
  }
}

And { "type": "module" } in package.json

Results in these error:

src/main.ts:4:5 - error TS2343: This syntax requires an imported helper named '__classPrivateFieldSet' which does not exist in 'tslib'. Consider upgrading your version of 'tslib'.

4     this.#relativePath = name;
      ~~~~~~~~~~~~~~~~~~

src/main.ts:8:12 - error TS2343: This syntax requires an imported helper named '__classPrivateFieldGet' which does not exist in 'tslib'. Consider upgrading your version of 'tslib'.

8     return this.#relativePath;
             ~~~~~~~~~~~~~~~~~~

Reverting to tslib 2.5.0 resolves these issues.

See: tslib-issue.zip

andrewbranch commented 1 year ago

Duplicate of #203, 2.5.2 was already published

nicojs commented 1 year ago

This is not a duplicate. The bug persists in v2.5.2.

Sorry I wasn't clear about that @andrewbranch 😓

andrewbranch commented 1 year ago

See https://github.com/microsoft/tslib/issues/203#issuecomment-1565902818

I think we have to patch TS itself for this, unfortunately