Skip to content

No error accessing private property with indexed access #26328

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

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

No error accessing private property with indexed access #26328

ghost opened this issue Aug 9, 2018 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@ghost
Copy link

ghost commented Aug 9, 2018

TypeScript Version: 3.1.0-dev.20180809

Code

class A { private n!: number; }
const a = new A();
const nameN = "n";
const n = a[nameN];

Expected behavior:

Error at a[nameN] just like for a.n.

Actual behavior:

No error.

@ghost ghost added the Bug A bug in TypeScript label Aug 9, 2018
@RyanCavanaugh RyanCavanaugh added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Bug A bug in TypeScript labels Aug 9, 2018
@RyanCavanaugh
Copy link
Member

This is an intended allowed bypass; see https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#413-property-access which outlines accessibility rules for a.x but not a["x"]

@ajafff
Copy link
Contributor

ajafff commented Aug 28, 2018

I wrote a linter rule to check accessibility of element access the same way TypeScript checks property access: no-restricted-property-access
For a description on how to use it, see https://github.com/fimbullinter/wotan/blob/master/packages/wotan/README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants