Skip to content

No error accessing private property in destructuring assignment #26355

Closed

Description

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

Activity

  1. ghost added
    BugA bug in TypeScript
    on Aug 10, 2018
  2. ghost added
    FixedA PR has been merged for this issue
    on Aug 11, 2018
  3. ghost closed this as completedin #26381on Aug 13, 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

Assignees

No one assigned

    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