Skip to content

Violation of encapsulation #26957

Closed
Closed
@ghost

Description

Hi all,
I've tested the following code:

class TestPrivate {
    public publicField: number;
    private privateField: number;
    constructor(pr: number, pub: number) {
        this.privateField = pr;
        this.publicField = pub;
    }

}

const obj1 = new TestPrivate(123, 789);

const temp = { fakeWrapper: obj1 };

const { fakeWrapper: { privateField } } = temp;

console.log(privateField);

And I see in console 123 output. It seems that we have a violation of encapsulation here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions