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

Suggestion: Constructor<T> and Class<T> #20256

Closed
na-sa-do opened this issue Nov 25, 2017 · 2 comments
Closed

Suggestion: Constructor<T> and Class<T> #20256

na-sa-do opened this issue Nov 25, 2017 · 2 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision

Comments

@na-sa-do
Copy link

na-sa-do commented Nov 25, 2017

type Constructor<T> = new(...x: any[]) => T;

type Class<T> = Constructor<T> & {
    prototype: T;
}

The use case for these should be fairly obvious. I'm separating them because, according to MDN, a constructor could choose to return an object that doesn't actually have the constructor's .prototype as its prototype -- but this doesn't actually work in Chrome for me; is that a bug in Chrome or an inaccuracy in MDN? I can't follow the spec well enough to tell either way.

It's worth noting that Constructor<T> should be revised if #5453 or #12265 get added, to the effect of

type Constructor<T, ...U> = {
    new(...U): T;
}

type Class<T, ...U> = Constructor<T, ...U> & {
    prototype: T;
}

but backwards compatibility there requires type argument defaults (I swear I've seen a proposal for that, but I can't find it, or I'd link it too); maybe it would be better to prefix these versions with Vague or something to that effect?

@mhegazy
Copy link
Contributor

mhegazy commented Nov 27, 2017

We limit the number of additional declarations added to the library to avoid namespace pollution, and to limit back-compat liabilities. You are welcome to define these type aliases as noted above in your own project and leverage them as needed.

@mhegazy mhegazy added the Declined The issue was declined as something which matches the TypeScript vision label Nov 27, 2017
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision
Projects
None yet
Development

No branches or pull requests

3 participants