Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@tinganho

Description

@tinganho
Issue body actions

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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScript

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.