Closed
Description
Bug Report
π Search Terms
π Version & Regression Information
- This changed between versions 4.2.3 and 4.3.0-dev.20210330
β― Playground Link
Playground link with relevant code
π» Code
class A {
private _x: number = 0;
get x() {
return this._x;
}
protected set x(v: number) {
this._x = v;
}
}
class B {
foo(this: A) {
this.x = 1; // Property 'x' is protected and only accessible through an instance of class 'B'. This is an instance of class 'A'.(2446)
}
}
function bar(this: A) {
this.x = 1; // This is OK.
}
π Actual behavior
The behavior of a protected setter is influenced by the accessibility of getter.
If you change the modifier of get x()
to protected
, the error will go away.
Also the error message is unclear. It says Property 'x' is protected and only accessible through an instance of class 'B'
, but x is only accessible through an instance of 'A', not 'B'.
π Expected behavior
No error.