I'd like to do this:
createClass(c:class):SomeInstance {
   return new class() as SomeInstance;
}
However, it says 'type expected' where I specify the :class part.
Fixed :
function createClass<SomeInstance>(c:{new():SomeInstance}):SomeInstance {
   return new c();
}
You are basically saying that createClass takes a constructor (something that when called with new gives an instance) hence c:{new():SomeInstance}. And then the return type of createClass is that SomeInstance
PS: probably call it
createInstance🌹
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With