Skip to content

Exempt declare redeclarations from TS2729 use-before-init check - #65518

Open
刘亦达 (zhengdaodeguL) wants to merge 1 commit into
microsoft:mainfrom
zhengdaodeguL:fix/ts2729-declare-redeclared-inherited-prop-65514
Open

刘亦达 (zhengdaodeguL) wants to merge 1 commit into
microsoft:mainfrom
zhengdaodeguL:fix/ts2729-declare-redeclared-inherited-prop-65514

Conversation

@zhengdaodeguL

Copy link
Copy Markdown

A field initializer reading an inherited property redeclared with declare
was incorrectly reported as TS2729:

class Base { b: 1 = 1; }
class Narrowed extends Base {
    declare b: 1 | 2;
    d = this.b; // error TS2729: Property 'b' is used before its initialization.
}

declare produces no emit, and the base field is already initialized inside
super(), so b is 1 by the time d initializes. This is a regression
from #43194, which removed the ancestor-class exemption under
useDefineForClassFields for redeclarations without initializers (b;
overwrites the property with undefined) but also caught declare
redeclarations; its tests only covered the non-declare case.

This PR exempts declare redeclarations from the use-before-initialization
check in both the JS checker (src/compiler/checker.ts, via the
tsc/testdata/fixtures copy) and the Go checker
(tsc/internal/checker/checker.go): for ancestor properties, TS2729 is now
reported under useDefineForClassFields only when the value declaration is
not 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), declare redeclaration (no error), and
ordinary redeclaration (TS2564, TS2612, TS2729). The focused Go harness
passes, as do all existing useBeforeDeclaration tests; on the base commit
the new test fails with the spurious TS2729 for the declare case.

Fixes #65514.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 18:36
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 15, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@zhengdaodeguL
刘亦达 (zhengdaodeguL) force-pushed the fix/ts2729-declare-redeclared-inherited-prop-65514 branch from 0ee8f1c to 5f638f6 Compare November 15, 2026 18:37

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you update this test fixture

@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

TS2729 when a field initializer reads an inherited property redeclared with declare

3 participants