There seems to be an inconsistency, although it may turn out to be by design.
In the example below, the compiler determines the type of variable b, but ignores the fact it is private. To be consistent, it should either:
- Not infer the type, or
- Infer the type and check access
Obviously in your case you are after the second of these options.
class Example {
private private: number;
public public: number;
constructor() {
this.private = 1
}
}
var example = new Example()
var a = example.private; // Error
var b = example["private"]; // number
var c = example["other"]; // any
var d = example["public"]; // number
I have raised an issue for this on GitHub.