Im trying to define a pure class based mixin function, but I cannot get the type signature right for this one.
The intent is to provide a function that accepts any Class A as parameter and returns a new Class B that extends the original Class A.
export function mixin<A>(myclass: A) {
return class B extends A {
newMethod() {
//stuff
}
}
}
As I said, I cannot figure this out.
I need a way to express that A needs to be a class.
I also need to express the return type, which yields several errors, among:
error TS4060: Return type of exported function has or is using private name 'B'.
Additional information:
- This is inside a
utils.tsmodule that is exported so that other modules can use it - This is all being worked in the context of a library I am writing
typeof A.just inheritance, it kind of is! But the difference is that you can add methods and attributes to A just like the old mixin would do