Created
November 6, 2017 22:48
-
-
Save vitkon/6b4618bcb46baddfd48e7404fc79d5a6 to your computer and use it in GitHub Desktop.
Typescript mixin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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