Improve error message for accessing instance properties via super - #64304
Open
Rave Viner (raveviner) wants to merge 1 commit into
Open
Rave Viner (raveviner) wants to merge 1 commit into
Rave Viner (raveviner) wants to merge 1 commit into
Conversation
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
🟡 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'.": { |
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.
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 throughthis. The message now reads: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
superAccessProtectedInstancePropertycovers theprotectedfield example from the issue.This PR was written with the help of Claude Code.