Skip to content

TS allow access private class field without error #10516

Closed
@terbooter

Description

@terbooter

TypeScript Version:

$ tsc -v
Version 1.8.10

Create file app.ts with following content:

class User {
    constructor(private name:string) {

    }

    public hello(who:User) {
        // name is the private property of object 'who'. TS should show error like
        // "Cat access private field 'name'"
        console.log("Hello, " + who.name);
    }
}

var vasya = new User("VASYA");
var peter = new User("PETER");
vasya.hello(peter);

Compile this file

tsc app.ts

Actual behavior:
You will see no error.

Expected behavior:
It should show error
"Cat access private field 'name'"

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