Title: TS2729 when a field initializer reads an inherited property redeclared with `declare` · Issue #65514 · microsoft/TypeScript · GitHub
Open Graph Title: TS2729 when a field initializer reads an inherited property redeclared with `declare` · Issue #65514 · microsoft/TypeScript
X Title: TS2729 when a field initializer reads an inherited property redeclared with `declare` · Issue #65514 · microsoft/TypeScript
Description: 🔎 Search Terms TS2729, used before its initialization, declare, useDefineForClassFields 🕗 Version & Regression Information This changed between versions 4.2.3 and 4.3.5 (#43194). It still reproduces in 6.0.3 and 7.1.0-dev.20261114.1. Fro...
Open Graph Description: 🔎 Search Terms TS2729, used before its initialization, declare, useDefineForClassFields 🕗 Version & Regression Information This changed between versions 4.2.3 and 4.3.5 (#43194). It still reproduce...
X Description: 🔎 Search Terms TS2729, used before its initialization, declare, useDefineForClassFields 🕗 Version & Regression Information This changed between versions 4.2.3 and 4.3.5 (#43194). It still repro...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/65514
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TS2729 when a field initializer reads an inherited property redeclared with `declare`","articleBody":"### 🔎 Search Terms\n\nTS2729, used before its initialization, declare, useDefineForClassFields\n\n### 🕗 Version & Regression Information\n\n- This changed between versions 4.2.3 and 4.3.5 (#43194).\n- It still reproduces in 6.0.3 and `7.1.0-dev.20261114.1`. From 6.0 the default target enables `useDefineForClassFields`, so it reproduces with no options set.\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play/?useDefineForClassFields=true&target=99&ts=6.0.3#code/MYGwhgzhAEBCkFNoG8BQ0PQEYC5oDsBXAWywQCdoBeaARgG5UBfVVUSGABXAEt9oEADwAuCfABMY8CEjSZo46tGEALHhAB0WetAD0u6AHkA0s1bso0AHJhy5APYB3BIqGiJUxCnSZxCduRIuHTQAD7QAEyM8oo0qupaOvoCdvaUACoAyhEA7BEAnHicDgAOFMIAntAA5FjV0OrQhDKKZABmaUg8wjB83TxgIDwAXmDCPPb4GmZskxD2IAgaIPYA5gAU+AiO1rYOzuLrAJQa4kdJBrSoQA\n\n### 💻 Code\n\n(The Playground does not derive `useDefineForClassFields` from the target, so the link above enables it explicitly.)\n\n```ts\nclass Base {\n b: number = 1;\n}\n\nclass Plain extends Base {\n d = this.b; // OK\n}\n\nclass Narrowed extends Base {\n declare b: 1 | 2;\n d = this.b; // error TS2729: Property 'b' is used before its initialization.\n}\n\nconsole.log(new Narrowed().d); // 1\n```\n\n### 🙁 Actual behavior\n\n`this.b` in `Narrowed` reports TS2729.\n\n### 🙂 Expected behavior\n\nNo error, as in `Plain`. Per the spec, the base class's fields are initialized inside `super()`, and the derived class's fields right after `super()` returns ([SuperCall evaluation](https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation)). `declare` emits nothing, so `b` is already initialized (`1`) when `d` is initialized. #42319 also lists this as expected: \"`c` is allowed because of the `declare` modifier\".\n\n### Additional information about the issue\n\n- #43194 removed the ancestor-class exemption under `useDefineForClassFields`, for the case where a redeclaration without an initializer (`b;`) overwrites the property with `undefined` ([DefineField](https://tc39.es/ecma262/#sec-definefield)). It also catches `declare` redeclarations, which emit nothing. The test it added covers only the case without `declare`.\n- TS2612 suggests adding `declare` to such a redeclaration, and doing so produces this error.\n- The same error occurs with `declare context: React.ContextType\u003c…>`, as recommended by `@types/react`, when a field initializer reads `this.context`.\n- Found while testing my own TypeScript compiler (https://github.com/mizchi/ts.mbt).","author":{"url":"https://github.com/mizchi","@type":"Person","name":"mizchi"},"datePublished":"2026-11-15T14:29:33Z","url":"https://github.com/microsoft/TypeScript/issues/65514"}
| 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:6d328c2c-3dd4-852c-75e3-f751a1f86d35 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9A10:DB09F:67CB2C:85D42B:6B00E197 |
| html-safe-nonce | 40db43f3f1d15ca9e9d497748e8b15ba143b3f2545a2bd92d7f3acd7c2e2a861 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QTEwOkRCMDlGOjY3Q0IyQzo4NUQ0MkI6NkIwMEUxOTciLCJ2aXNpdG9yX2lkIjoiODkwNjY0MjMxNjgxMTM2MjcxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3ae69b6941f24136474fc882dca2315e3578d887bd4c7159752064b648d3b300 |
| hovercard-subject-tag | issue:6405203001 |
| 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/65514/issue_layout |
| twitter:image | https://opengraph.githubassets.com/24549159182038d3a6ae0575209044184b2481855850085c2214a00c5aee5377/microsoft/TypeScript/issues/65514 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/24549159182038d3a6ae0575209044184b2481855850085c2214a00c5aee5377/microsoft/TypeScript/issues/65514 |
| og:image:alt | 🔎 Search Terms TS2729, used before its initialization, declare, useDefineForClassFields 🕗 Version & Regression Information This changed between versions 4.2.3 and 4.3.5 (#43194). It still reproduce... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mizchi |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width