Title: Class private members accessible from outside with brackets notation · Issue #19335 · microsoft/TypeScript · GitHub
Open Graph Title: Class private members accessible from outside with brackets notation · Issue #19335 · microsoft/TypeScript
X Title: Class private members accessible from outside with brackets notation · Issue #19335 · microsoft/TypeScript
Description: I'm concerned about private members being "legally" accessible from outside the class, since it could lead people to believe it's an acceptable way for doing it in production code. Currently, my team believes this is an acceptable way fo...
Open Graph Description: I'm concerned about private members being "legally" accessible from outside the class, since it could lead people to believe it's an acceptable way for doing it in production code. Currently, my te...
X Description: I'm concerned about private members being "legally" accessible from outside the class, since it could lead people to believe it's an acceptable way for doing it in production code...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/19335
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Class private members accessible from outside with brackets notation","articleBody":"I'm concerned about private members being \"legally\" accessible from outside the class, since it could lead people to believe it's an acceptable way for doing it in production code.\r\nCurrently, my team believes this is an acceptable way for unit testing code.\r\n\r\nThis approach even detects the correct private member's type, so it's not a workaround to access the raw members through upcast to any...\r\n\r\n**TypeScript Version:** 2.4\r\n\r\n**Code**\r\n\r\n```ts\r\nclass Test {\r\n constructor(private _x: number) { }\r\n getValue(): number { return this._x; }\r\n}\r\nlet t = new Test(10);\r\nt[\"_x\"] = -6;\r\n```\r\n\r\n**Expected behavior:**\r\nCompiler error: \"Property '_x' is private and only accessible within the class 'Test'\".\r\n\r\n**Actual behavior:**\r\nNo errors.\r\n","author":{"url":"https://github.com/marcomura","@type":"Person","name":"marcomura"},"datePublished":"2017-10-19T10:24:01Z","url":"https://github.com/microsoft/TypeScript/issues/19335"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:92a30842-4ed3-bdef-c77a-9105799e9299 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC38:6DC60:26CBD3:309376:6B00FF20 |
| html-safe-nonce | 77a0132c99ee3166189a1f05cafdef4c4caa562665ea45ee3ff6f8ee74ae5158 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzM4OjZEQzYwOjI2Q0JEMzozMDkzNzY6NkIwMEZGMjAiLCJ2aXNpdG9yX2lkIjoiMzQwMzY3MDAwNjU4MjU0MjExMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b24309d7118b961f4139f5a9efb506a57c0091bd8ec638f46dedbeaaffeefb1f |
| hovercard-subject-tag | issue:266793109 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/19335/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7ffe94e65ecf9ff8d262bbd6162c318d2a98d17da3d8d541836f95ffee7b3f94/microsoft/TypeScript/issues/19335 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7ffe94e65ecf9ff8d262bbd6162c318d2a98d17da3d8d541836f95ffee7b3f94/microsoft/TypeScript/issues/19335 |
| og:image:alt | I'm concerned about private members being "legally" accessible from outside the class, since it could lead people to believe it's an acceptable way for doing it in production code. Currently, my te... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | marcomura |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width