-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
private
class property is unprotected if key is numeric
#50485
Comments
This is an intended behavior. See #19335. |
I am aware of how the indexed access notation works, this issue is specifically about numeric properties. I believe that the computed property notation is an escape hatch. It is not intended to forbid class properties from using the privacy feature when their key is numeric. A numeric property can only be accessed using the bracket notation. I am not opting-in to the indexed access, I'm not accessing it using |
Here is the limitation: Any property access inside square brackets will ignore |
The fact that Typescript allows making that property private, but actually never enforces its privacy is a bug. It should either not allow privacy modifiers on numeric properties because they're defacto not supported or it should enforce privacy when accessing that property. |
Numeric names are certainly very rare and breaking someone's program on purpose to fix the perceived inconsistency doesn't seem like a great trade-off here. |
As came up in #60974 (comment), |
Bug Report
π Version & Regression Information
ts stable & nightly
β― Playground Link
Playground Link
π» Code
π Actual behavior
Writing
foo[1337]
is denied because it is areadonly
class property.Reading
foo[1337]
is allowed although it is aprivate
class property.π Expected behavior
Reading
foo[1337]
throws an error because it is a private class property.The text was updated successfully, but these errors were encountered: