Title: code gen depends on types · Issue #20125 · microsoft/TypeScript · GitHub
Open Graph Title: code gen depends on types · Issue #20125 · microsoft/TypeScript
X Title: code gen depends on types · Issue #20125 · microsoft/TypeScript
Description: TypeScript Version: 2.6.1 Code class Foo { bar(): void { console.log(this.x); } } class Bar extends Foo { x: Number; constructor() { super(); this.x = 2; } bar() { super.bar(); (super.bar as any)(); } } let b = new Bar(); b.bar() Expecte...
Open Graph Description: TypeScript Version: 2.6.1 Code class Foo { bar(): void { console.log(this.x); } } class Bar extends Foo { x: Number; constructor() { super(); this.x = 2; } bar() { super.bar(); (super.bar as any)()...
X Description: TypeScript Version: 2.6.1 Code class Foo { bar(): void { console.log(this.x); } } class Bar extends Foo { x: Number; constructor() { super(); this.x = 2; } bar() { super.bar(); (super.bar as any)()...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/20125
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"code gen depends on types","articleBody":"**TypeScript Version:** 2.6.1\r\n\r\n**Code**\r\n\r\n```ts\r\nclass Foo {\r\n bar(): void {\r\n console.log(this.x);\r\n }\r\n}\r\n\r\nclass Bar extends Foo {\r\n x: Number;\r\n\r\n constructor() {\r\n super();\r\n this.x = 2;\r\n }\r\n\r\n bar() {\r\n super.bar();\r\n (super.bar as any)();\r\n }\r\n} \r\n\r\nlet b = new Bar();\r\nb.bar()\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nI expect that the code generated for `super.bar()` and `(super.bar as any)()` behave the same - this code should console.log(2) twice.\r\n\r\n**Actual behavior:**\r\n\r\nThe code logs 2, and then undefined.\r\n\r\nThe underlying issue is that `super.bar()` and `(super.bar as any)()` compile to different code. the former compiles to `_super.prototype.bar.call(this);`, but the `as any` changes the compilation to `_super.prototype.bar();`, and so `super.bar` is called with the wrong `this` when the cast is in place.\r\n\r\nI was generally under the impression that code generation should be the same whether or not casts were present in the code, so I found this a bit surprising. that said, it was easy to change my code to avoid this pitfall.","author":{"url":"https://github.com/dgoldstein0","@type":"Person","name":"dgoldstein0"},"datePublished":"2017-11-18T04:36:55Z","url":"https://github.com/microsoft/TypeScript/issues/20125"}
| 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:785970b2-731a-f3d4-75e5-1fa781d73f7e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B894:3DE7C3:222DD80:2B96853:6B03DF9B |
| html-safe-nonce | 3d5371a2dfe76b72a77ea0dcd215778e3174e0938e45f471739ae71143e3fd8f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODk0OjNERTdDMzoyMjJERDgwOjJCOTY4NTM6NkIwM0RGOUIiLCJ2aXNpdG9yX2lkIjoiMzA1NDAyODE5MDg3MzAxODI2NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bebde276c14193f8389be0328c712168d697a39501f343ec0063f8bcf292c4c2 |
| hovercard-subject-tag | issue:275052761 |
| 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/20125/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3724d6240f804430869a86c69eefa81fcb545cd9b65523cac3f285423da0bb7e/microsoft/TypeScript/issues/20125 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3724d6240f804430869a86c69eefa81fcb545cd9b65523cac3f285423da0bb7e/microsoft/TypeScript/issues/20125 |
| og:image:alt | TypeScript Version: 2.6.1 Code class Foo { bar(): void { console.log(this.x); } } class Bar extends Foo { x: Number; constructor() { super(); this.x = 2; } bar() { super.bar(); (super.bar as any)()... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dgoldstein0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width