Skip to content

Private members of outer accessible to class expressions #17535

Closed
@penguin020

Description

@penguin020

(TypeScript Version: 2.4.1 stable)

Code
Here is a use case of class expressions that allows access to the private members of the outer class.

fyi: I actually like this behavior, but it is probably a bug.

    class classX { 
        private y: number = 0; 
    
        public getY(): number { return this.y; }
        
    	public utilities = new class {
    		constructor(public superThis: classX) {
    		}
    		public testSetOuterPrivate(target: number) {
                this.superThis.y = target;
    		}
    	}(this);    
    }
    
    const x1: classX = new classX();

    alert(x1.getY());

    x1.utilities.testSetOuterPrivate(4);
    alert(x1.getY());

codepen

Expected behavior:
this.superThis.y should blow an access error on compilation

Actual behavior:
this.superThis.y does not blow an access error on compilation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions