Title: Private variable in a class is treated as public in the transpiled code · Issue #9733 · microsoft/TypeScript · GitHub
Open Graph Title: Private variable in a class is treated as public in the transpiled code · Issue #9733 · microsoft/TypeScript
X Title: Private variable in a class is treated as public in the transpiled code · Issue #9733 · microsoft/TypeScript
Description: Correct me if I am wrong. There is something fundamentally wrong in the transpilation. I created a class called Person with an intention to keep the name private to the class and expose it via a method. The transpiled code is making the ...
Open Graph Description: Correct me if I am wrong. There is something fundamentally wrong in the transpilation. I created a class called Person with an intention to keep the name private to the class and expose it via a me...
X Description: Correct me if I am wrong. There is something fundamentally wrong in the transpilation. I created a class called Person with an intention to keep the name private to the class and expose it via a me...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/9733
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Private variable in a class is treated as public in the transpiled code","articleBody":"Correct me if I am wrong. There is something fundamentally wrong in the transpilation.\n\nI created a class called Person with an intention to keep the name private to the class and expose it via a method. The transpiled code is making the field ( defined as private) public, however , in typescript code - it prevents the direct access of private fields outside the constructor function and prototype\n\nMy get method is added to the prototype. This is wrong. It should be part of the function constructor itself. \n\nIs there a way to get this in transpiler ?\n\nPlease find the transpiled code and what it should have been ( ideally)\n\nTranspiled code\n\n'use strict';\nvar Person = (function () {\n function Person(name) {\n this._name = name;\n }\n ;\n Person.prototype.getName = function () {\n return 'Name : ' + this._name;\n };\n return Person;\n}());\nvar p = new Person('John');\nconsole.log(p.getName());\n\nWhat it should have been ideally\n\n'use strict';\nvar Person = (function () {\n\nlet _name;\n function Person(name) {\n _name = name;\n\n```\n this.getName = function () {\n return 'Name : ' + _name;\n};\n};\n\nreturn Person;\n```\n\n}());\nvar p = new Person('John');\nconsole.log(p.getName());\nconsole.log(p._name); //not accessible\n","author":{"url":"https://github.com/smangalath","@type":"Person","name":"smangalath"},"datePublished":"2016-07-14T12:28:43Z","url":"https://github.com/microsoft/TypeScript/issues/9733"}
| 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:78209518-075d-59a3-ae25-e328b192066e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BEA4:E3C4F:78273C:9AF69E:6B00E69E |
| html-safe-nonce | 6f5e4187184c82cad8cfc3c4eda63ad267d0038a9cc95fd698d69c511eca79bf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRUE0OkUzQzRGOjc4MjczQzo5QUY2OUU6NkIwMEU2OUUiLCJ2aXNpdG9yX2lkIjoiNDU5NDg0OTUyOTM3ODk1Njk1OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 69b2735574bafd32bc680bfd731d4e37019d4b2c278bc6cc0bb7c3dfbb121634 |
| hovercard-subject-tag | issue:165550138 |
| 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/9733/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4fe808c4a9cea6c8e2ddb5e0664711fbe1bd8f0c1ec6ad41bf6a1b8713c3e34e/microsoft/TypeScript/issues/9733 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4fe808c4a9cea6c8e2ddb5e0664711fbe1bd8f0c1ec6ad41bf6a1b8713c3e34e/microsoft/TypeScript/issues/9733 |
| og:image:alt | Correct me if I am wrong. There is something fundamentally wrong in the transpilation. I created a class called Person with an intention to keep the name private to the class and expose it via a me... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | smangalath |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width