Closed
Description
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?
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
mhegazy commentedon 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.
typescript-bot commentedon Dec 12, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.