Skip to content

Improve error message for accessing instance properties via super - #64304

Open
Rave Viner (raveviner) wants to merge 1 commit into
microsoft:mainfrom
raveviner:fix-super-instance-property-message
Open

Rave Viner (raveviner) wants to merge 1 commit into
microsoft:mainfrom
raveviner:fix-super-instance-property-message

Conversation

@raveviner

Copy link
Copy Markdown

Fixes #55883

Error 2855 previously read "Class field '{0}' defined by the parent class is not accessible in the child class via super.", which suggests the problem is related to accessibility modifiers like protected. The real cause is that the member is an instance property, which lives on the instance rather than the prototype, so it must be accessed through this. The message now reads:

Instance property '{0}' is defined by the superclass and must be accessed through 'this', not 'super'.

The diagnostic code is unchanged. Generated diagnostics and localization bundles were regenerated, existing baselines were updated for the new text, and a new compiler test superAccessProtectedInstanceProperty covers the protected field example from the issue.

This PR was written with the help of Claude Code.

Copilot AI balanced review requested due to automatic review settings September 17, 2026 05:44
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 17, 2026
@typescript-automation typescript-automation Bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Sep 17, 2026
@raveviner

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

🟡 Changes recommended

TS2855 now incorrectly recommends this for private superclass properties, which remain inaccessible from subclasses.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates TS2855 to clarify that superclass instance properties cannot be accessed through super.

Changes:

  • Revises the diagnostic text and checker reference.
  • Adds the issue’s protected-field regression test.
  • Regenerates affected compiler baselines.
File summaries
File Description
tsc/testdata/tests/cases/compiler/superAccessProtectedInstanceProperty.ts Adds protected-field regression case.
tsc/testdata/baselines/reference/conformance/protectedInstanceMemberAccessibility(target=es2015).errors.txt Updates TS2855 baseline.
tsc/testdata/baselines/reference/conformance/protectedClassPropertyAccessibleWithinSubclass3(target=es2015).errors.txt Updates TS2855 baseline.
tsc/testdata/baselines/reference/conformance/privateInstanceMemberAccessibility(target=es2015).errors.txt Updates private-field diagnostic baseline.
tsc/testdata/baselines/reference/conformance/parserAstSpans1(target=es2015).errors.txt Updates TS2855 baseline.
tsc/testdata/baselines/reference/conformance/errorSuperPropertyAccess(target=es2015).errors.txt Updates super-property diagnostics.
tsc/testdata/baselines/reference/compiler/superPropertyAccess(target=es2015).errors.txt Updates property-access diagnostics.
tsc/testdata/baselines/reference/compiler/superInLambdas(target=es2015).errors.txt Updates lambda diagnostics.
tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.types Adds type baseline.
tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.symbols Adds symbol baseline.
tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.js Adds emit baseline.
tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.errors.txt Adds diagnostic baseline.
tsc/testdata/baselines/reference/compiler/superAccess(target=es2015).errors.txt Updates TS2855 baseline.
tsc/testdata/baselines/reference/compiler/classFieldSuperNotAccessibleJs.errors.txt Updates JavaScript diagnostic baseline.
tsc/testdata/baselines/reference/compiler/classFieldSuperNotAccessible.errors.txt Updates class-field diagnostic baseline.
tsc/testdata/baselines/reference/compiler/checkSuperCallBeforeThisAccess.errors.txt Updates constructor-access diagnostics.
tsc/internal/diagnostics/diagnostics_generated.go Regenerates diagnostic definitions.
tsc/internal/diagnostics/diagnosticMessages.json Defines the revised TS2855 text.
tsc/internal/checker/checker.go Uses the renamed diagnostic.
Review details

Files not reviewed (1)

  • tsc/internal/diagnostics/diagnostics_generated.go: Generated file
  • Files reviewed: 18/32 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

"code": 2854
},
"Class field '{0}' defined by the parent class is not accessible in the child class via super.": {
"Instance property '{0}' is defined by the superclass and must be accessed through 'this', not 'super'.": {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Misleading error message for super.instanceProperty

2 participants