microsoft / microsoft/TypeScript

Bug: Accessing private statics in a class via its derived class is allowed

Open
#8,624 22 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Breaking Change Effort: Moderate Help Wanted Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version:

1.8.X

Code

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

    testBase(): void {
        console.log(FooBase.privateStatic);

        // Should error, but doesn't
        console.log(Foo.privateStatic);
   }
}

class Foo extends FooBase {
    test() {
        // Should error, and does
        console.log(Foo.privateStatic);
    }
}

Expected behavior:
Accessing Foo.privateStatic shouldn't be allowed, regardless of the context it's called in.

Actual behavior:
FooBase is allowed to do this.

(thanks @sethbrenith for deducing this)

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

Start by reproducing the supplied FooBase/Foo code with the TypeScript 1.8.x checker and compare the two private static accesses. Trace the type-checking path for static member visibility; done means both accesses to Foo.privateStatic produce the expected error, including the one inside FooBase.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.