microsoft / microsoft/TypeScript

Misleading error message for `super.instanceProperty`

Open
#55,883 6 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: Error Messages Rescheduled
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Take the following code:

export abstract class YaddaBase {
    protected roots = "hi";
}

export class DerivedYadda extends YaddaBase {
    public get rootTests() {
        return super.roots;
    }
}

TypeScript nightly (5.3.0-dev.20230926) reports:

Class field 'roots' defined by the parent class is not accessible in the child class via super.

The error message here is confusing - one might believe that this has to do with accessing a member with a protected modifier, but it is really about accessing an instance field with super. A better error message would be:

'roots' is defined as an instance property and must be accessed through 'this', not 'super'.

We can also provide a quick fix for this error message.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic with the TypeScript snippet and inspect where the reported message is defined. Done means the diagnostic clearly explains that an instance property must be accessed through this rather than super, with the proposed quick fix assessed as part of the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.