Repository navigation
Exempt declare redeclarations from TS2729 use-before-init check - #65518
Open
刘亦达 (zhengdaodeguL) wants to merge 1 commit into
Open
刘亦达 (zhengdaodeguL) wants to merge 1 commit into
刘亦达 (zhengdaodeguL) wants to merge 1 commit into
Conversation
刘亦达 (zhengdaodeguL)
force-pushed
the
fix/ts2729-declare-redeclared-inherited-prop-65514
branch
from
November 15, 2026 18:37
0ee8f1c to
5f638f6
Compare
There was a problem hiding this comment.
why did you update this test fixture
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A field initializer reading an inherited property redeclared with
declarewas incorrectly reported as TS2729:
declareproduces no emit, and the base field is already initialized insidesuper(), sobis1by the timedinitializes. This is a regressionfrom #43194, which removed the ancestor-class exemption under
useDefineForClassFieldsfor redeclarations without initializers (b;overwrites the property with
undefined) but also caughtdeclareredeclarations; its tests only covered the non-
declarecase.This PR exempts
declareredeclarations from the use-before-initializationcheck in both the JS checker (
src/compiler/checker.ts, via thetsc/testdata/fixturescopy) and the Go checker(
tsc/internal/checker/checker.go): for ancestor properties, TS2729 is nowreported under
useDefineForClassFieldsonly when the value declaration isnot ambient. Non-ancestor properties are unaffected, and ordinary
redeclarations without initializers still report TS2729 (plus TS2564 and
TS2612), preserving #43194.
Added a baselines test case
(
useBeforeDeclaration_declareRedeclaration.ts) covering all three branches:plain inheritance (no error),
declareredeclaration (no error), andordinary redeclaration (TS2564, TS2612, TS2729). The focused Go harness
passes, as do all existing
useBeforeDeclarationtests; on the base committhe new test fails with the spurious TS2729 for the
declarecase.Fixes #65514.