Skip to content

Destructuring with private and protected members #7124

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
xLama opened this issue Feb 17, 2016 · 1 comment
Closed

Destructuring with private and protected members #7124

xLama opened this issue Feb 17, 2016 · 1 comment
Assignees
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@xLama
Copy link

xLama commented Feb 17, 2016

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?

@DanielRosenwasser DanielRosenwasser added By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Question An issue which isn't directly actionable in code Bug A bug in TypeScript and removed By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Question An issue which isn't directly actionable in code labels Feb 17, 2016
@DanielRosenwasser
Copy link
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.

@mhegazy mhegazy added this to the TypeScript 2.0 milestone Feb 24, 2016
@mhegazy mhegazy added Fixed A PR has been merged for this issue Breaking Change Would introduce errors in existing code labels Feb 26, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants