Skip to content

Instantly share code, notes, and snippets.

@GokselKUCUKSAHIN
Created January 6, 2022 19:58
Show Gist options
  • Save GokselKUCUKSAHIN/e587032a30298869a3b79aed3863da1e to your computer and use it in GitHub Desktop.
Save GokselKUCUKSAHIN/e587032a30298869a3b79aed3863da1e to your computer and use it in GitHub Desktop.
TypeScript Multiple Inheritance using Mixins.
import {using, Disposable} from "using-statement";
import {Mixin} from "ts-mixer";
import {EventEmitter} from "events";
class Walker {
walk() {
console.log("walking...");
}
}
class Jumper {
jump() {
console.log("jumping...");
}
}
// extending 3 Class
class MyComplexClass extends Mixin(EventEmitter, Walker, Jumper) implements Disposable {
private readonly _name: string;
constructor(name = "n/A") {
super();
this._name = name;
}
get name(): string {
return this._name;
}
dispose(): void {
console.log("disposed.");
}
}
using(new MyComplexClass("sqrt(-1)"), complex => {
console.log(complex.name);
complex.jump();
complex.walk();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment