Skip to content

Cannot use protected constructor of a parent's parent #12256

Closed
@westy92

Description

@westy92

TypeScript Version: 2.0.9

Code

class Base {
    protected constructor() { }
    public instance1 = new Base(); // allowed
}

class Subclass extends Base {
    public instance1_1 = new Base(); // allowed
    public instance1_2 = new Subclass(); // allowed
}

class SubclassOfSubclass extends Subclass {
    public instance2_1 = new Base(); // error
    public instance2_2 = new Subclass(); // error
    public instance2_3 = new SubclassOfSubclass(); // error
}

Expected behavior:
Calling a protected constructor of a parent's parent is allowed.

Actual behavior:
test.ts(12,26): error TS2674: Constructor of class 'Base' is protected and only accessible within the class declaration.
test.ts(13,26): error TS2674: Constructor of class 'Base' is protected and only accessible within the class declaration.
test.ts(14,26): error TS2674: Constructor of class 'Base' is protected and only accessible within the class declaration.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions