I am looking to devise an interface or a type that contains static properties and a constructor signature. My goal is to utilize this interface/type as a parameter for a function. I experimented with using an interface, but encountered limitations in declaring static fields within it. I also attempted utilizing an abstract class structured as shown below:
interface IClassType {
instanceMethod: (param: string) => void;
}
abstract class IBaseClass {
static requiredProperty: string;
static optionalProperty?: boolean;
abstract new (param: number): IClassType;
}
I proceeded by attempting to apply the abstract class as a type within a function setup similar to the one outlined below:
// @param UserClass: must implement or extend IBaseClass
const demoFunction = (UserClass: IBaseClass) => {
const demoClass = new UserClass(3);
// Triggers a compiler error:
// "Type 'IBaseClass' has no construct signatures."
const demoProp = UserClass.requiredProperty;
// Triggers a compiler error:
// "Property 'requiredProperty' does not exist on type 'IBaseClass'.
// Did you mean to access the static member
// 'IBaseClass.requiredProperty' instead?"
}
Assistance in resolving this issue would be highly valued.