Skip to content

Destructuring with private and protected members #7124

Description

@xLama
class Foo {

    private sayFoo = () => {
        console.log('Foo')
    }

}

let foo = new Foo();
foo.sayFoo() // Error. It´s ok.

let {sayFoo} = foo;
sayFoo() // 'Foo' 

Is it by design?

Activity

  1. added
    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead
    QuestionAn issue which isn't directly actionable in code
    BugA bug in TypeScript
    and removed
    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead
    QuestionAn issue which isn't directly actionable in code
    on Feb 17, 2016
  2. DanielRosenwasser commented on Feb 17, 2016

    @DanielRosenwasser
    Member

    Clearer case:

    class Foo {
        private prop;
    }
    let foo = new Foo();
    
    let a = foo.prop;
    let { prop: b } = foo;
    let { prop } = foo;

    foo.prop in the declaration of a causes an error because prop is private. The destructuring cases don't.

  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Breaking ChangeWould introduce errors in existing codeBugA 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