I would like to create a mixin, that can use a mehod of the class into which it was mixed. However this is not working.
////////////////////
// Simple class
class User {
sayHello(msg:string){
console.log(msg)
}
}
// Needed for all mixins
type Constructor<T = {}> = new (...args: any[]) => T;
////////////////////
// A mixin that adds a method that uses a base class method
function Activatable<TBase extends Constructor>(Base: TBase) {
return class extends Base {
activate() {
(Base as unknown as User).sayHello("activated")
}
};
}
////////////////////
// Using the composed class
////////////////////
const ActivableUser = Activatable(User)
const activableUser = new ActivableUser()
activableUser.activate()
Run fails with [ERR]: Base.sayHello is not a function .
Is there any way I can create a mixin that has access to base class methods and properties?