You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
export type Constructor<T> = new(...args: any[]) => T;
or maybe even:
export type Class<T> = new(...args: any[]) => T;
It's easy enough to hand-roll, but just feels like something that ought to be built into the language?
π Motivating Example
This pattern is already used extensively in many on-line code examples. E.g. see here: https://dev.to/kalashin1/utility-types-in-typescript-4nfo - although this post suggests TypeScript already has this feature, whereas as far as I can tell, it actually doesn't!
π» Use Cases
I've used the Angular Type utility type quite extensively in my Angular application, whenever I want to pass around classes for some reason, whilst also keeping track of their associated instance types.
The text was updated successfully, but these errors were encountered:
The team decided against adding more utility types, unless they're needed for emit purposes. There's even a PR that will add "not a request for a utility type" to the viability checklist: #55746
And of course there's already #26990, #54428, #20256 and many more. Used search terms: constructor type in:title
π Search Terms
Class Constructor utility type
β Viability Checklist
β Suggestion
Angular includes a
Type
utility type which is defined like this:I think this could be more succinctly defined, and I think the word "Type" here is a little misleading, as this actually denotes a class/constructor.
I'm wondering though, why TypeScript doesn't have a built-in equivalent? (Or if it does, why I can't find it, and it isn't documented here: https://www.typescriptlang.org/docs/handbook/utility-types.html)
I was thinking something like this:
or maybe even:
It's easy enough to hand-roll, but just feels like something that ought to be built into the language?
π Motivating Example
This pattern is already used extensively in many on-line code examples. E.g. see here: https://dev.to/kalashin1/utility-types-in-typescript-4nfo - although this post suggests TypeScript already has this feature, whereas as far as I can tell, it actually doesn't!
π» Use Cases
I've used the Angular
Type
utility type quite extensively in my Angular application, whenever I want to pass around classes for some reason, whilst also keeping track of their associated instance types.The text was updated successfully, but these errors were encountered: