-
Notifications
You must be signed in to change notification settings - Fork 143
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
TypeScript definite assignment assertions are not removed for private class fields #639
Comments
Afaik that syntax is not valid in TypeScript, and this seems to compile alright: class A { #b!: number } |
My bad, I guess I went too far with minimizing the test case. Still, I believe this: class A { #b!: number; } Should compile down to this: class A { #b; } not this, which isn't valid JavaScript: class A { #b!; } |
Thanks for reporting! A related problem I found while investigating is that even non-private fields have problems here when using class A { b!: number; } becomes this: class A { b!; } I think I have a fix working, will put up a PR soon. |
Fixes #639 Previously, the `!` operator for class field declarations was not treated as a type token, so it wasn't automatically removed at transpile. In most cases, this wasn't relevant because the class field transform removes uninitialized fields completely. However, there are two cases where it causes an issue: * `disableESTransforms: true`, which disables the class field transform. * Private fields, which are skipped by the class field transform. In both cases, we can fix the issue by just setting the `!` as a type token so that it will naturally get removed by the TS transformer. I also did a little refactoring to pull out the logic for handling individual type tokens.
Fixes #639 Previously, the `!` operator for class field declarations was not treated as a type token, so it wasn't automatically removed at transpile. In most cases, this wasn't relevant because the class field transform removes uninitialized fields completely. However, there are two cases where it causes an issue: * `disableESTransforms: true`, which disables the class field transform. * Private fields, which are skipped by the class field transform. In both cases, we can fix the issue by just setting the `!` as a type token so that it will naturally get removed by the TS transformer. I also did a little refactoring to pull out the logic for handling individual type tokens.
Hi! Thanks for a great tool, it's been wonderful using it for instant TypeScript-to-JavaScript conversion in my projects.
The TypeScript transform should remove the
!
definite assignment assertion for private class fields:The expected result is:
But instead, the
!
is currently kept.Example: https://sucrase.io/#selectedTransforms=typescript&code=class%20A%20%7B%20%23b!%3B%20%7D
The text was updated successfully, but these errors were encountered: