-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
TS allow access private class field without error #10516
Comments
BTW, This only occurs when the classes are the same: class Foo {
constructor(private name: string) {
}
}
class User {
constructor(private name:string) {
}
public hello(who: Foo) {
console.log("Hello, " + who.name); // Property 'name' is private and is only accessible from within class 'Foo'
}
}
var vasya = new User("VASYA");
var peter = new Foo("PETER");
vasya.hello(peter); |
Like in most other languages, classes may access private members of other instances of the same class. |
@RyanCavanaugh could you please give examples of such languages. |
I think
|
That would still apply... @terbooter there is PHP and C# and Java and pretty much every other OO language. |
The only language I'm aware of that uses instance-based visibility instead of type-based visibility is Ruby. Java, C#, C++, Swift, PHP, etc. all allow access to other instances' private members. |
Thanks for your answers. |
TypeScript Version:
Create file app.ts with following content:
Compile this file
Actual behavior:
You will see no error.
Expected behavior:
It should show error
"Cat access private field 'name'"
The text was updated successfully, but these errors were encountered: