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
When writing a TypeScript decorator, it's useful to have a type representing any function or class that can be instantiated. This can be described using a custom type like:
typeInstantiable=new(...args: never)=>unknown;
This allows you describe an instantiable function or class without resorting to any or unknown. I think that including this utility type as part of the built in TypeScript types would be helpful.
π Motivating Example
I created a library a while ago can serialize instances of classes. I wrote a Serializable decorator that registers classes for serialization. The decorator needs to access target.prototype which doesn't work if target is unknown.
Suggestion
π Search Terms
instantiable, utility type
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
When writing a TypeScript decorator, it's useful to have a type representing any function or class that can be instantiated. This can be described using a custom type like:
This allows you describe an instantiable function or class without resorting to
any
orunknown
. I think that including this utility type as part of the built in TypeScript types would be helpful.π Motivating Example
I created a library a while ago can serialize instances of classes. I wrote a
Serializable
decorator that registers classes for serialization. The decorator needs to accesstarget.prototype
which doesn't work iftarget
isunknown
.π» Use Cases
The easiest solution is just to declare your own
Instantiable
type. You can also useunknown
orany
, which are less than ideal.The text was updated successfully, but these errors were encountered: