-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Default target esnext
is not applied to TypeScript
#2012
Comments
This is intentional because in TypeScript specifying If esbuild did as you suggested, then people's working TypeScript code would be broken when building with esbuild. That's why this behavior is opt-in for esbuild. It's unfortunate that TypeScript originally went with class field semantics for their language and it's also unfortunate that they are now trying to change it (especially how subtly they are doing it). But I understand wanting to align TypeScript semantics with JavaScript semantics and don't know how they could make this transition more smooth (besides communicating more clearly about the change). I may change this once ES2022 comes out. The way this actually works in the TypeScript compiler is that if |
with typescript 4.6, there's
|
That's really weird. There is no ES2022 yet: https://tc39.es/ecma262/2022/ returns 404 (see https://tc39.es/ecma262/2021/ and earlier for comparison). |
That might be the case, but as far as typescript is concerned.... |
Ok. I added an |
@evanw Is there anything else needed, now that https://tc39.es/ecma262/2022/ is available? Or are we safe using ES2022 as the target? Thanks! |
This is going to be fixed in the next release. In the next release, this will be both esbuild's default behavior (without any flags) and esbuild's behavior with class MyClass {
_propertyOne = 1;
_propertyTwo = 2;
printProperties() {
console.log(this._propertyOne, this._propertyTwo);
}
}
new MyClass().printProperties(); and this will be esbuild's behavior with var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
class MyClass {
constructor() {
__publicField(this, "_propertyOne", 1);
__publicField(this, "_propertyTwo", 2);
}
printProperties() {
console.log(this._propertyOne, this._propertyTwo);
}
}
new MyClass().printProperties(); In other words, esbuild will now always use define semantics for class fields by default. You will now have to explicitly configure esbuild to use assign semantics using class MyClass {
constructor() {
this._propertyOne = 1;
this._propertyTwo = 2;
}
printProperties() {
console.log(this._propertyOne, this._propertyTwo);
}
}
new MyClass().printProperties(); So I consider this issue to be fixed. |
I have the following TypeScript code saved in a file called
index.ts
:If I run
esbuild
without any options, the documentation says that the default target isesnext
. But that doesn't seem to be the case at least for TypeScript since I get two different outputs whether I specify the target or not.Without target:
npx esbuild index.ts
With target:
npx esbuild index.ts --target=esnext
Here is some additional information.
tsconfig
file is used:tsconfig
with the target set toesnext
it is picked up and I could runesbuild
without options and get the code without aconstructor
..js
and remove theprivate
keywords, I get the desiredesnext
level code that doesn't use the constructor without having to specify atarget
.Is it intended that the default target
esnext
doesn't seem to apply to TypeScript or is this a bug? I searched through other issues and found this comment: #923 (comment) which to me sounds like theesnext
default should apply to TypeScript.The text was updated successfully, but these errors were encountered: