Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule to detect non-public property access via element access #375

Closed
ajafff opened this issue Aug 9, 2018 · 2 comments
Closed

Add rule to detect non-public property access via element access #375

ajafff opened this issue Aug 9, 2018 · 2 comments

Comments

@ajafff
Copy link
Member

ajafff commented Aug 9, 2018

class Foo {
    private bar = 1;
}
let foo = new Foo();

foo.bar; // type error
foo['bar']; // can access private property

Although prefer-dot-notation disallows element access where possible, but there are still property names like 'foo-bar' that need to use element access. TypeScript intentionally doesn't check accessibility on element access for reasons ... (see microsoft/TypeScript#26328)

This is likely an error and should be detected by a lint rule

@ajafff
Copy link
Member Author

ajafff commented Aug 10, 2018

Depending on how microsoft/TypeScript#26356 and microsoft/TypeScript#26355 are resolved, this rule should detect these cases, too.

@ajafff
Copy link
Member Author

ajafff commented Aug 12, 2018

It turns out there are a lot more checks that are simply ignored for element access:

  • super['abstractMethod']
  • super['prop']
  • this['abstractProp'] in constructor
  • a['protectedProp']: accessing protected property declared in base class on an instance of a base class in a static method of a derived class (or a function with a this parameter of a derived class)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant