You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript support class field syntax before it is standardized.
And TypeScript's class field has different semantics with native class field.
This is why useDefineForClassFields exists.
When target is set to es2022 or higher, TypeScript will use native class field semantics.
But you should not rely on the behavior of target default value.
You should always set useDefineForClassFields to true or false explicitly.
Once it works in TypeScript, it will work in swc.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Describe the bug
When transpiling to
es2015
, swc initializes an uninitialized class property toundefined
:When
es2022
is used, it does not initialize the property:Similarly, tsc and esbuild skip the initialization.
Input code
Config
Playground link
https://play.swc.rs/?version=1.3.87&code=H4sIAAAAAAAAA0vOSSwuVnBKLE5VqOZSUEhJLEm0UsgrzU1KLVKwVTDkquXiSq0oyC8qUUgGq3TLz1dIrShJzUtB0gXRpwjTyFULABjS7aVWAAAA&config=H4sIAAAAAAAAA1VPSQ7CMAy85xWRzxwACQ78gUdEwa2Csil2JaKqfydpk0Jv9iye8SykhDdpeMi5jGWJKhGmfS8IZc%2FqUxDgHJF0MpHh1FmmSg3KEq7QsjHAKo3I1YV0PV9uzQE2BMLuaJgz3gz5P1MHFxMSHYVVqvxo8ZgoWiq48JpWsv1S%2B24N7vAT9bD9MBh6dienCcXyBbnuEC8XAQAA
SWC Info output
No response
Expected behavior
Skip the initialization of uninitialized class properties when target is
es2015
-2021
output.It's not initializing to
undefined
when target ises2022
.Actual behavior
By setting the uninitialized property's value to
undefined
, it overrides the property value set in the base class.Version
1.3.87
Additional context
Related issue: #3232
The text was updated successfully, but these errors were encountered: