Title: useDefineWithClassFields should use-before-init error when class property initializer refers to parameter property · Issue #50971 · microsoft/TypeScript · GitHub
Open Graph Title: useDefineWithClassFields should use-before-init error when class property initializer refers to parameter property · Issue #50971 · microsoft/TypeScript
X Title: useDefineWithClassFields should use-before-init error when class property initializer refers to parameter property · Issue #50971 · microsoft/TypeScript
Description: Bug Report This bug exists in my project, not only playground, but playground seem to also have bugs, because i can't even seem to reliably reproduce it in the playground – sometimes it does not react on Target change. But right now i ha...
Open Graph Description: Bug Report This bug exists in my project, not only playground, but playground seem to also have bugs, because i can't even seem to reliably reproduce it in the playground – sometimes it does not re...
X Description: Bug Report This bug exists in my project, not only playground, but playground seem to also have bugs, because i can't even seem to reliably reproduce it in the playground – sometimes it does no...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/50971
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"useDefineWithClassFields should use-before-init error when class property initializer refers to parameter property","articleBody":"# Bug Report\r\n\r\nThis bug exists in my project, not only playground, but playground seem to also have bugs, because i can't even seem to reliably reproduce it in the playground – sometimes it does not react on `Target` change. But right now i have an opened playground tab with this bug.\r\n\r\nI will duplicate the MRE code right here as a text.\r\nThis is the source code\r\n\r\n```typescript\r\nclass Helper {\r\n create(): boolean {\r\n return true\r\n }\r\n}\r\n\r\nexport class Broken {\r\n\r\n constructor(readonly facade: Helper) {\r\n console.log(this.bug)\r\n }\r\n bug = this.facade.create()\r\n\r\n}\r\n\r\nnew Broken(new Helper)\r\n```\r\n\r\nThis is the compiled code with `target: ES2022` and `module: CommonJS`\r\n\r\n```js\r\n\"use strict\";\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nexports.Broken = void 0;\r\nclass Helper {\r\n create() {\r\n return true;\r\n }\r\n}\r\nclass Broken {\r\n facade;\r\n constructor(facade) {\r\n this.facade = facade;\r\n console.log(this.bug);\r\n }\r\n bug = this.facade.create();\r\n}\r\nexports.Broken = Broken;\r\nnew Broken(new Helper);\r\n```\r\n\r\nIf run this JS – we will get TypeError\r\n\r\n```error\r\nCannot read properties of undefined (reading 'create') \r\n```\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?target=9&module=1&ts=4.8.2&noImplicitUseStrict=true#code/MYGwhgzhAEASCmIAO8BO0DeAoavrFXjABd4AKASgC5oAjAe3pCIDtMc9PDiBXVN4qh7wOuAL5YJWeAA8k9VMXzgo0AEKp6Aa3htso-PRYRBPYMQVlCYACZGQAT2gAzMMFvwaCZGgrtOnMBGEEzwAHQg9ADmZMQAFgCWEGG0PFEUBhKcqVHQALzQ8Ulhru424QREpJRYkrVYLPAA7uqaOixkjS3eKKgUQA)\r\n\r\n\r\nI'm also sharing the playground link, but i assume it could produce the right code for you if you open it first time.\r\nTo reliable reproduce – change `module` to `Node16` and then to `CommonJS`. You should see this result\r\n\r\n\u003cimg width=\"959\" alt=\"Screen Shot 2022-09-27 at 19 54 16\" src=\"https://user-images.githubusercontent.com/9336742/192588709-e036c3cf-6cdc-4aa6-b070-85d267a4862a.png\">\r\n","author":{"url":"https://github.com/dilame","@type":"Person","name":"dilame"},"datePublished":"2022-09-27T16:55:57Z","url":"https://github.com/microsoft/TypeScript/issues/50971"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:0a273f1e-eeb4-adc8-0818-9dd602310780 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8552:137C1B:C6C1B9:1043C3B:6AED4DFF |
| html-safe-nonce | 059417bef2e0149c8bf6fc286ed7e8da13e53cd45c9c110eff62964d86d436d0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTUyOjEzN0MxQjpDNkMxQjk6MTA0M0MzQjo2QUVENERGRiIsInZpc2l0b3JfaWQiOiI1NjIxMjMyNjQzMDg1MjU4MjM5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b4579638e8f8d42e8647829125ff4aa3d009b2d3676ec0172db7b777b171c166 |
| hovercard-subject-tag | issue:1388075885 |
| 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/50971/issue_layout |
| twitter:image | https://opengraph.githubassets.com/47cd1f3dccc7c8755484bcdaa2e9c09d5ea0c675b087c90ce035c5d411658849/microsoft/TypeScript/issues/50971 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/47cd1f3dccc7c8755484bcdaa2e9c09d5ea0c675b087c90ce035c5d411658849/microsoft/TypeScript/issues/50971 |
| og:image:alt | Bug Report This bug exists in my project, not only playground, but playground seem to also have bugs, because i can't even seem to reliably reproduce it in the playground – sometimes it does not re... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dilame |
| hostname | github.com |
| expected-hostname | github.com |
| None | 56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11 |
| 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 | 9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width