Skip to content

Misleading error message for super.instanceProperty #55883

Open
@DanielRosenwasser

Description

@DanielRosenwasser

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingRescheduledThis issue was previously scheduled to an earlier milestone

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions