Title: Why are TS get/set definedProperties in a class transpiled as enumerable/writable? · Issue #3610 · microsoft/TypeScript · GitHub
Open Graph Title: Why are TS get/set definedProperties in a class transpiled as enumerable/writable? · Issue #3610 · microsoft/TypeScript
X Title: Why are TS get/set definedProperties in a class transpiled as enumerable/writable? · Issue #3610 · microsoft/TypeScript
Description: I just confirmed in the TS Playground that the following TS: class Foo { get bar() { return true;} } Produces this JS: var Foo = (function () { function Foo() { } Object.defineProperty(Foo.prototype, "bar", { get: function () { return tr...
Open Graph Description: I just confirmed in the TS Playground that the following TS: class Foo { get bar() { return true;} } Produces this JS: var Foo = (function () { function Foo() { } Object.defineProperty(Foo.prototyp...
X Description: I just confirmed in the TS Playground that the following TS: class Foo { get bar() { return true;} } Produces this JS: var Foo = (function () { function Foo() { } Object.defineProperty(Foo.prototyp...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/3610
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Why are TS get/set definedProperties in a class transpiled as enumerable/writable?","articleBody":"I just confirmed in the TS Playground that the following TS:\n\n```\nclass Foo {\n get bar() { return true;}\n}\n```\n\nProduces this JS:\n\n```\nvar Foo = (function () {\n function Foo() {\n }\n Object.defineProperty(Foo.prototype, \"bar\", {\n get: function () { return true; },\n enumerable: true,\n configurable: true\n });\n return Foo;\n})();\n```\n\nThis [MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) confirms that, for `Object.definedProperty` accessors:\n• enumerable: Defaults to false.\n• configurable: Defaults to false.\n\nClearly the generated code is overriding the default values for these keys.\n\nPlowing through the ES6 spec is not something I do. So I’m not sure that ES6 hasn’t changed the defaults. But I’d be surprised.\n\nNow one of the things I miss in TS/ES6 class definitions is the ability to control these keys. It is also not easy to embellish a class with defined properties later … properties that might have non-default definitions\n\nBut that’s not my point or my question … which is, why is TS deviating from the defaults? \n\nI get why I’d want the property to be enumerable most of the time – strange that the spec defaults to false. I don’t understand why I should want it to be configurable (maybe because I don't like something about the property TS generated for me?).\n\nIn any case, I don’t get how TS (or ES6) gets away with changing the ES5 defaults.\n","author":{"url":"https://github.com/wardbell","@type":"Person","name":"wardbell"},"datePublished":"2015-06-24T00:31:29Z","url":"https://github.com/microsoft/TypeScript/issues/3610"}
| 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:97f6ac8c-6033-a178-4cd9-4a877d9ab8ac |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D23E:21AC3F:9984F1:C62EB7:6B00DDB4 |
| html-safe-nonce | a62df055502a241c5e6d976f839dc91fdcc8e9365073fc6a0486fbcab62f4706 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjNFOjIxQUMzRjo5OTg0RjE6QzYyRUI3OjZCMDBEREI0IiwidmlzaXRvcl9pZCI6IjE5OTcyMDQxNjU3NDIzNTM4NDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c70674acbdf7a64ab0cd2cf971dabd4b0273944066ac33e2f083243604cd68b2 |
| hovercard-subject-tag | issue:90526297 |
| 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/3610/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b166657554a72f6f291771d1e1241cfdb94302ea13e1d899636c5b065cd9d266/microsoft/TypeScript/issues/3610 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b166657554a72f6f291771d1e1241cfdb94302ea13e1d899636c5b065cd9d266/microsoft/TypeScript/issues/3610 |
| og:image:alt | I just confirmed in the TS Playground that the following TS: class Foo { get bar() { return true;} } Produces this JS: var Foo = (function () { function Foo() { } Object.defineProperty(Foo.prototyp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | wardbell |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width