Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

new rule: Respect static member privacy #169

@leemiro

Description

@leemiro

TypeScript behaves unintuitively when a base class references its private static variable via a derived class, as follows:

class FooBase {
    private static privateStatic: string = "unset";

    testPrivateStatic(): void {
        Foo.privateStatic = "set";
        console.log(FooBase.privateStatic);
   }
}

class Foo extends FooBase { }

// Logs "unset" but you'd expect it to log "set"
new FooBase().testPrivateStatic();

There is an issue open against TypeScript here, but until that's fixed (and after, for older versions of TypeScript), we should have a rule that prohibits referencing derived classes' private statics since the behavior of doing such is likely not what the developer expects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions