GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Report self-references in parameter property initializers by bodapatisaikrishna · Pull Request #65401 · microsoft/TypeScript

Conversation

@bodapatisaikrishna

@bodapatisaikrishna bodapatisaikrishna commented Nov 9, 2026

Copy link
Copy Markdown

Fixes #62414

Problem
constructor(private f = f) {} compiles without an error and throws a ReferenceError at runtime. The same code with a plain parameter reports TS2372.

Cause
The binder declares a parameter property twice: a parameter symbol in the constructor's locals and a property symbol in the class members. The node's symbol ends up being the property. The self-reference check in onSuccessfullyResolvedSymbol compared the resolved parameter symbol with getSymbolOfDeclaration(...), so they never matched.

Change
Compare the resolved symbol's value declaration with the parameter declaration instead. This needs no name matching, and deferred references such as private g = () => g() stay legal.

Testing
Added selfReferencesInParameterProperties, covering direct self-reference, a shadowed outer variable, later and earlier parameters, and deferred use. Without the fix it reports no TS2372. go test ./internal/testrunner/... passes and no existing baselines changed. Checker, binder, compiler and 19 other packages pass, as does hereby check:format. I couldn't finish hereby test or run hereby lint locally because of disk space, so I'm relying on CI for those.

This patch was written with AI assistance (Claude Code). I have read it, understand it, and will handle review myself.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bodapatisaikrishna
Report self-references in parameter property initializers
6ad227e
`constructor(private f = f) {}` compiled without an error and threw a
ReferenceError at runtime, while the same code with a plain parameter
reported TS2372.

The binder declares a parameter property twice, as a parameter symbol
in the constructor's locals and as a property symbol in the class
members, and the node's symbol ends up being the property. The
self-reference check compared the resolved parameter symbol with the
declaration's symbol, so the two never matched.

Compare the resolved symbol's value declaration with the parameter
declaration instead.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 07:42
@github-project-automation github-project-automation Bot added this to PR Backlog Nov 9, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Nov 9, 2026
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 9, 2026
Copilot stopped reviewing on behalf of bodapatisaikrishna due to an error November 9, 2026 07:44
The "Prepare Copilot (Linux)" step in the Copilot workflow failed before the agent could finish.
Copilot AI reviewed Nov 9, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Note

Copilot was unable to run its full agentic suite in this review.

Copilot review overview

No open issues 🎉

What changed in this PR

Adds a compiler regression test for resolving self-references inside parameter properties, and adjusts the checker logic to correctly detect self-references for parameter properties (where the “parameter” symbol can actually be represented by the synthesized class property symbol).

Changes:

  • Added a new compiler test case covering direct self-reference, shadowing, and forward/backward parameter references in parameter properties.
  • Updated checker logic to compare declarations (not symbols) when detecting self-references in parameter initializers for parameter properties.
  • Added new baselines (types/symbols/js/errors) for the test.
File Description
tsc/​testdata/​tests/​cases/​compiler/​selfReferencesInParameterProperties.ts New test case covering self-reference scenarios in parameter properties.
tsc/​testdata/​baselines/​reference/​compiler/​selfReferencesInParameterProperties.types Type baseline for the new test.
tsc/​testdata/​baselines/​reference/​compiler/​selfReferencesInParameterProperties.symbols Symbol baseline for the new test.
tsc/​testdata/​baselines/​reference/​compiler/​selfReferencesInParameterProperties.js Emit baseline for the new test.
tsc/​testdata/​baselines/​reference/​compiler/​selfReferencesInParameterProperties.errors.txt Error baseline asserting expected diagnostics.
tsc/​internal/​checker/​checker.go Fixes self-reference detection by comparing the resolved symbol’s value declaration to the initializer’s containing declaration.

Review effort: Lite

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

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

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

PR Backlog
Status: Not started

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

TypeScript fails to detect self-reference issue in "Parameter Properties" of constructors

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@bodapatisaikrishna
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.