-
-
Notifications
You must be signed in to change notification settings - Fork 470
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
transformer: class constructor argument access modifier special behavior #4789
Comments
Thanks for the detailed issue! The oxc transformer port from |
OK great. Do we have a test for the 2nd case TS Playground? |
It looks like you have this under control. I wanted to mention that |
Thank you @robpalme explain this more! |
If I understand correctly, the case should be like, The output has a difference with TypeScript. But it doesn’t matter, the output is consident with |
### Description A small update for * oxc-project/oxc#4789
In TypeScript, the following class (case 1) reports a type error:
Because it will be transformed to:
TS Playground
However, if it uses access modifier on the constructor argument (case 2):
It will work both in types and at runtime, because it will be transformed to:
TS Playground
Notice how
x = this.foo
is moved into the constructor to be after thethis.foo
assignment.Oxc's current behavior
Oxc currently transforms case 2 to:
Notice that both
x = this.foo
andconsole.log(this.foo)
are executed before thethis.foo
assignment, both leading to runtime errors.What needs to be fixed
Related: Behavior with
useDefineForClassFields: true
When
useDefineForClassFields
is set to true, case 2 will also throw a type error. And TS's transform out will become:TS Playground
I'm not sure if oxc's TS transform currently takes this into account, but this is something we will need to consider.
The text was updated successfully, but these errors were encountered: