Title: Expected behaviour of __extends with static accessors? · Issue #1520 · microsoft/TypeScript · GitHub
Open Graph Title: Expected behaviour of __extends with static accessors? · Issue #1520 · microsoft/TypeScript
X Title: Expected behaviour of __extends with static accessors? · Issue #1520 · microsoft/TypeScript
Description: The following code: var i = 0, j = 0; class Base { get instanceAccessor() { return ++i; } static get staticAccessor() { return ++j; } toString = () => 'instance: ' + this.instanceAccessor + ' static: ' + Base.staticAccessor; } class Deri...
Open Graph Description: The following code: var i = 0, j = 0; class Base { get instanceAccessor() { return ++i; } static get staticAccessor() { return ++j; } toString = () => 'instance: ' + this.instanceAccessor + ' stati...
X Description: The following code: var i = 0, j = 0; class Base { get instanceAccessor() { return ++i; } static get staticAccessor() { return ++j; } toString = () => 'instance: ' + this.instanceAccesso...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/1520
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Expected behaviour of __extends with static accessors?","articleBody":"The following code:\n\n``` typescript\nvar i = 0, j = 0;\n\n\nclass Base {\n get instanceAccessor() { return ++i; }\n static get staticAccessor() { return ++j; }\n toString = () => 'instance: ' + this.instanceAccessor + ' static: ' + Base.staticAccessor;\n}\n\n\nclass Derived extends Base {\n toString = () => 'instance: ' + this.instanceAccessor + ' static: ' + Derived.staticAccessor;\n}\n\n\nconsole.log('Base:\\n%s\\n%s\\n%s', new Base(), new Base(), new Base());\nconsole.log('Derived:\\n%s\\n%s\\n%s', new Derived(), new Derived(), new Derived());\n```\n\ngenerates the following output (with the v1.3 compiler):\n\n```\nBase:\ninstance: 1 static: 2\ninstance: 2 static: 3\ninstance: 3 static: 4\nDerived:\ninstance: 4 static: 1\ninstance: 5 static: 1\ninstance: 6 static: 1\n```\n\nClearly `Derived.staticAccessor` is no longer an accessor, but a 'snapshot' of the value of `Base.staticAccessor` when the `Derived` constructor function called `__extends`.\n\nJust wondering if this is the expected/correct behaviour?\n\nPS. I haven't run into this problem 'in the wild' as I rarely use classes or accessors, but merely came across a [rant/blog post](http://toshokelectric.com/blog/2013/04/04/why-im-ditching-coffeescript/) about another compile-to-JS language doing something similar, and was curious how TypeScript handled it.\n","author":{"url":"https://github.com/yortus","@type":"Person","name":"yortus"},"datePublished":"2014-12-17T05:28:53Z","url":"https://github.com/microsoft/TypeScript/issues/1520"}
| 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:7bdb7033-7fd0-41f0-e48a-c80e9bc0c043 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D7CA:31B4CC:4FB509:6AF167:6B00CC55 |
| html-safe-nonce | b3c3cfbd5328f0e94d6eae3bada3aa303ddfcfca3c2ef09173e8a970ddf05648 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEN0NBOjMxQjRDQzo0RkI1MDk6NkFGMTY3OjZCMDBDQzU1IiwidmlzaXRvcl9pZCI6IjM2Mzk0NjEyMTU3NTY5MzAxMzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 866db4b3c96038a65ca00cf24db53024cfdf98a9abfe2c344b293e94ad94c98b |
| hovercard-subject-tag | issue:52203182 |
| 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/1520/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9974fc00c8a8c7c3040ff2927ea8a4741b25abe12c2f7ff8cfa081ef1e8958bf/microsoft/TypeScript/issues/1520 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9974fc00c8a8c7c3040ff2927ea8a4741b25abe12c2f7ff8cfa081ef1e8958bf/microsoft/TypeScript/issues/1520 |
| og:image:alt | The following code: var i = 0, j = 0; class Base { get instanceAccessor() { return ++i; } static get staticAccessor() { return ++j; } toString = () => 'instance: ' + this.instanceAccessor + ' stati... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yortus |
| hostname | github.com |
| expected-hostname | github.com |
| None | 98dc00e171c204462a6f367482a0f8c3c6b5dbca99cd7390e82d2df49ce096e4 |
| 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 | ef013399cf0a3c324bea644a685d7c1e0f06b5b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width