Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow this typing and type parameters on static methods #7627

Closed
tinganho opened this issue Mar 22, 2016 · 2 comments
Closed

Allow this typing and type parameters on static methods #7627

tinganho opened this issue Mar 22, 2016 · 2 comments
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@tinganho
Copy link
Contributor

Since constructor visibility #2341 got merged. I haven't been able to utilise it fully because the classes I can benefit from requires type parameters and this typings on static methods.

abstract class Model<P> {
    static create(props: P): this {
        let model = window.store[this.name + props.id];
        if (model) {
            return model;
        }
        return window.store[this.name + props.id] = new this(props)
    }

    protected constructor(props: P) {
    }
}

The Model class is a base class. A this typing would be very good to refer to the subclass instead of the base class. Since many classes has type arguments in their constructors, it makes sense to allow type arguments in static factory methods as well, otherwise you cannot create type safe factory methods.

@tinganho
Copy link
Contributor Author

Also since the original reason to allow visibility on constructors was to support static factory methods. So at least this typing on static methods needs to be supported to conform to the original reason.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 28, 2016

duplicate of #5863

@mhegazy mhegazy added Suggestion An idea for TypeScript Duplicate An existing issue was already created labels Mar 28, 2016
@mhegazy mhegazy closed this as completed Mar 28, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants