Skip to content

No error accessing private property in destructuring assignment #26355

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
ajafff opened this issue Aug 10, 2018 · 0 comments · Fixed by #26381
Closed

No error accessing private property in destructuring assignment #26355

ajafff opened this issue Aug 10, 2018 · 0 comments · Fixed by #26381
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 destructuring

Code

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

let bar: number;
({bar} = foo); // no error
({bar: bar} = foo); // no error

Expected behavior:

Error on both destructuring assignments.

Since element access on private properties is allowed (#26328), how would you expect the following to behave?

({'bar': bar} = foo);
({['bar']: bar} = foo);

Actual behavior:

No error

Playground Link: https://agentcooper.github.io/typescript-play/#code/MYGwhgzhAEBiD29oG8BQ0PQA4CcCWAbmAC4Cm0ARmDtALzQCMA3KgL6oinHQBmid0AHakA7nEQAKAJQsOXStQBcQgK4BbCqRwsJyKjlYC+8GdAD0ZoUi054OVLv3L9h+sdMWr0G3aA

Related Issues: #26328

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
2 participants