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?