mirror of
https://github.com/swc-project/swc.git
synced 2024-12-18 11:11:30 +03:00
37 lines
841 B
TypeScript
37 lines
841 B
TypeScript
// @target: esnext
|
|
// @declaration: true
|
|
|
|
interface Mixin {
|
|
mixinMethod(): void;
|
|
}
|
|
|
|
function Mixin<TBaseClass extends abstract new (...args: any) => any>(baseClass: TBaseClass): TBaseClass & (abstract new (...args: any) => Mixin) {
|
|
abstract class MixinClass extends baseClass implements Mixin {
|
|
mixinMethod() {
|
|
}
|
|
}
|
|
return MixinClass;
|
|
}
|
|
|
|
class ConcreteBase {
|
|
baseMethod() {}
|
|
}
|
|
|
|
abstract class AbstractBase {
|
|
abstract abstractBaseMethod(): void;
|
|
}
|
|
|
|
class DerivedFromConcrete extends Mixin(ConcreteBase) {
|
|
}
|
|
|
|
const wasConcrete = new DerivedFromConcrete();
|
|
wasConcrete.baseMethod();
|
|
wasConcrete.mixinMethod();
|
|
|
|
class DerivedFromAbstract extends Mixin(AbstractBase) {
|
|
abstractBaseMethod() {}
|
|
}
|
|
|
|
const wasAbstract = new DerivedFromAbstract();
|
|
wasAbstract.abstractBaseMethod();
|
|
wasAbstract.mixinMethod(); |