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

Error accessing private property in destructuring with computed property name #26356

Closed
ajafff opened this issue Aug 10, 2018 · 0 comments
Closed
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ajafff
Copy link
Contributor

ajafff commented Aug 10, 2018

TypeScript Version: 3.1.0-dev.20180808

Search Terms: private string access

Code

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

foo.bar; // error as expected
foo['bar']; // no error as expected

let {bar} = foo; // error as expected
let {'bar': bar2} = foo; // error (expected?)
let {['bar']: bar3} = foo; // error (expected?)

Expected behavior:

#26328 states that accessing non-public properties via element access with string literal or late-bound name is intentionally allowed.
To be consistent that should also apply to destructuring with computed property name or quoted name.

Actual behavior:

Errors as described by the inline comments.

Playground Link: https://agentcooper.github.io/typescript-play/#code/MYGwhgzhAEBiD29oG8BQ0PQA4CcCWAbmAC4Cm0ARmDtALzQCMA3KgL6oinHQBmid0AHakA7nEQAKAJQtUfeADoqOJtAD0a6KRw54NSFoAeWUsDIATOYgDaAcmW2Auqo1Ck23fpiljpi6g4uFGVWAXkXTQ89aAMfEzNSS05uZHtqWwAuSmoAJlD6cPVInWiJOL9EgH4pQJS7B0cs5QBmfN5ECK0SmjLfBPNqoA

Related Issues:
#26328
#26355

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants