I'm trying to build a mixin function that optionally expects a super class. The rationale is that we often just build intermediate classes to start off with our mixins. I am quite confident with the following declarations, but they don't work, however:
interface Test {
readonly __TEST: "test";
new (...args: any[]): {
readonly test: "test";
};
}
function TestMixin<SuperClass extends new (...args: any[]) => any>(
superClass?: SuperClass
) {
const defaultClass = class {};
/* Error: Type 'new (...args: any[]) => any' is not assignable to type 'SuperClass extends undefined ? typeof defaultClass : undefined'.ts(2322) */
const sc: typeof superClass extends undefined ? typeof defaultClass : undefined = superClass === undefined ? defaultClass : superClass;
/* Error: Type 'SuperClass extends undefined ? typeof defaultClass : undefined' is not a constructor function type. */
class T extends sc implements InstanceType<Test> {
public static readonly __TEST = "test";
public readonly test = "test";
}
return T;
}
typeof defaultClassNothing extendstypeof