Answer the question
In order to leave comments, you need to log in
How to use mixins on abstract classes?
// https://www.typescriptlang.org/docs/handbook/mixins.html
type Constructor<T = {}> = new (...args: any[]) => T;
type AbstractConstructor<T> = Function & { prototype: T };
// type ConstructorFunction = abstract new (...args: any[]) => any;
declare type ConstructorFunction<T extends Utilities> = new (...args: any[]) => T;
type Constructor2<T> = new (...args: any[]) => T
export default function Activatable<TBase extends Constructor2>(Base: TBase) {
return class extends Base {
// Mixins may not declare private/protected properties
// however, you can use ES2020 private fields
_scale = 111111111111111111111111;
_isActivated = false;
_timestamp = Date.now();
activate() {
this._isActivated = true;
}
deactivate() {
this._isActivated = false;
}
setScale(scale: number) {
this._scale = scale;
}
get scale(): number {
return this._scale;
}
};
}
import Activatable from '@/store/module/abstract/mixin/countdown.ts'
abstract class AbstractModuleForm {...}
abstract class AbstractModuleCountdownForm extends Activatable(AbstractModuleForm) {...}
class Test extends AbstractModuleCountdownForm {...}
Answer the question
In order to leave comments, you need to log in
Generic type 'Constructor2' requires 1 type argument(s).
function Activatable<TBase extends Constructor2>
Type 'TBase' is not a constructor function type.this error came out of the previous one
Cannot create an instance of an abstract class.
Cannot assign an abstract constructor type to a non-abstract constructor typeeverything swears correctly, abstract classes are abstract because they have abstract methods whose implementation must be in the heir, their construction will lead to errors and TS protects against this.
A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'.The mixin accepts an arbitrary abstract class as input, without knowing about all its abstract methods, so it must also be abstract.
This one is incorrect...type AbstractConstructor<T> = Function & { prototype: T };
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question