Closed
Description
TypeScript Version: 2.0.3
class C1 {
protected foo() {};
static generateFor(x:C1) {
const RetVal = new C1();
RetVal.foo(); //Compiler allows access of protected member from static method in the class itself
return RetVal;
}
}
class C2 extends C1 {
static generateFor(x:C2) {
const RetVal = new C1();
RetVal.foo(); //Compiler disallows access of protected member from static method in child class
//error TS2446: Property 'foo' is protected and only accessible through an instance of class 'C2'.
return RetVal;
}
}
Expected behavior: A static function in a class extending a class C can access all protected and public, but not private members of instances of C
Actual behavior: Protected members are not accessible,Compiler throws TS2446
For reference the simple case without inheritance, which works as expected:
- A static function in a class C can access all private,protected and public members of instances of C (works as expected)