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
I have a function that takes a class constructor as a parameter, and returns another class constructor of the same type. Internally, the provided constructor is subclassed and augmented, and the subclass is returned.
I'm having trouble finding a way to express this function in a generic, strongly-typed manner. Note the //ERROR comment in the repro code below:
Repro code:
// Base type of the family of classes operated on by the augment() functionclassFooClass{/*...*/}// ========== Works, but is not generic ==========functionaugment(SuperClass: typeofFooClass): typeofFooClass{classSubClassextendsSuperClass{/*...*/}returnSubClass;}varFooClass2=augment(FooClass);// ========== Generic, but does not compile ==========functiongenericAugment<TextendstypeofFooClass>(SuperClass: T): T{classSubClassextendsSuperClass{//ERROR: Type 'T' is not a constructor function type/*...*/}returnSubClass;}
I've tried a few other variations, but can't seem to find a way to express this pattern.
Is there any way to do it?
The text was updated successfully, but these errors were encountered:
I have a function that takes a class constructor as a parameter, and returns another class constructor of the same type. Internally, the provided constructor is subclassed and augmented, and the subclass is returned.
I'm having trouble finding a way to express this function in a generic, strongly-typed manner. Note the
//ERROR
comment in the repro code below:Repro code:
I've tried a few other variations, but can't seem to find a way to express this pattern.
Is there any way to do it?
The text was updated successfully, but these errors were encountered: