Skip to content

Instantly share code, notes, and snippets.

@vitkon
Created November 6, 2017 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitkon/6b4618bcb46baddfd48e7404fc79d5a6 to your computer and use it in GitHub Desktop.
Save vitkon/6b4618bcb46baddfd48e7404fc79d5a6 to your computer and use it in GitHub Desktop.
Typescript mixin
import { EventEmitter2 } from 'eventemitter2';
class Core extends EventEmitter2 {
constructor() {
super();
this.init();
}
init() {
console.log('initialised');
}
}
type Constructor<T = {}> = new (...args: any[]) => T;
function WithUsers<TBase extends Constructor>(Base: TBase) {
return class extends Base {
getUserById(id: number) {
return id;
}
};
}
export default WithUsers(Core);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment