Skip to content

Nested destructuring with private and protected members #26760

Description

TypeScript Version:
3.0.3
3.1.0-dev.20180829

Search Terms:
private fields destructuring
private members destructuring

Code

class Foo {
    private prop;
}
const foo = new Foo();
const bar = { foo };

// Errors
foo.prop;
const { prop: prop1 } = foo; 

// No error
const { foo: { prop: prop2 } } = bar;

Expected behavior:
Nested destructuring of private and protected members causes an error

Actual behavior:
It doesn't

Playground Link:
https://www.typescriptlang.org/play/index.html#src=class%20Foo%20%7B%0D%0A%20%20%20%20private%20prop%3B%0D%0A%7D%0D%0Aconst%20foo%20%3D%20new%20Foo()%3B%0D%0Aconst%20bar%20%3D%20%7B%20foo%20%7D%3B%0D%0A%0D%0A%2F%2F%20Errors%0D%0Afoo.prop%3B%0D%0Aconst%20%7B%20prop%3A%20prop1%20%7D%20%3D%20foo%3B%20%0D%0A%0D%0A%2F%2F%20No%20error%0D%0Aconst%20%7B%20foo%3A%20%7B%20prop%3A%20prop2%20%7D%20%7D%20%3D%20bar%3B%0D%0A%20

Related Issues:
#7124

Activity

  1. ghost added
    BugA bug in TypeScript
    on Aug 30, 2018
  2. ghost closed this as completedon Nov 17, 2018
  3. ghost added
    FixedA PR has been merged for this issue
    on Nov 17, 2018
  4. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions