Skip to content

Bug: Accessing protected members from a static function in a derived class is declined. #11832

Closed
@0815fox

Description

@0815fox

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions