I made a minimum reproduction of an error I'm encountering:
type Constructor<T = {}> = new (...args: any[]) => T
class Base {}
const myMixin = function <TBase extends Constructor>(Base: TBase) {
return class myMixin<T> extends Base {
doSomethingWith(value: T) {
//
}
}
}
export class MyMixedClass<T> extends myMixin(Base) {
}
Is this not possible? I get an error that's so counter-intuitive it comes across as a joke:
Class static side 'typeof MyMixedClass' incorrectly extends base class static side '{ prototype: myMixin<any>.myMixin<any>; } & typeof Base'.
Types of property 'prototype' are incompatible.
Type 'MyMixedClass<any>' is not assignable to type 'myMixin<any>.myMixin<any> & Base'.
Property 'doSomethingWith' is missing in type 'MyMixedClass<any>' but required in type 'myMixin<any>.myMixin<any>'.ts(2417)
main.ts(7, 9): 'doSomethingWith' is declared here.
It seems like what it's asking me to do (I didn't think for a second that this would work) is this:
constructor(...args: any[]) { super(...args) }
of course it doesn't work, because this isn't actually the problem. Does typescript see the generic as a complication of the constructor in some way? Is what I'm trying to do just not supported in typescript?