The following code:
class A {
constructor(public x: number) {
}
}
Since TypeScript 3.7, which added the useDefineForClassFields configuration1, it is translated into the following result with "useDefineForClassFields": true (playground), up to the latest version (5.9.3):
"use strict";
class A {
x;
constructor(x) {
this.x = x;
}
}
esbuild currently (0.27.4) generates the following code (playground):
class A {
constructor(x) {
this.x = x;
}
}
I think we should stay consistent with TypeScript.
related: microsoft/TypeScript#55132
The following code:
Since TypeScript 3.7, which added the
useDefineForClassFieldsconfiguration1, it is translated into the following result with"useDefineForClassFields": true(playground), up to the latest version (5.9.3):esbuild currently (0.27.4) generates the following code (playground):
I think we should stay consistent with TypeScript.
related: microsoft/TypeScript#55132
Footnotes
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier ↩