Skip to content

Protected constructors should be accessible on subclasses's static methods #9734

Closed
@tinganho

Description

@tinganho

I think the below should be allowed.

class A {
    protected constructor() {

    }
}

class B extends A {
    static create() {
        new B(); // ERROR, but should not error.
    }
}

I wanted to override a static factory and customise it a bit. But it seems like I wasn't allowed to do it.

And my motivation is that private constructors are accessible on a class's static methods.

class A {
    static create() {
        new this();
    }
    protected constructor() {

    }
}

And a natural extension of the private case is to allow protected constructors on subclasses's static methods.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions