Created
January 16, 2020 19:18
-
-
Save FFKL/34d552a1d3c285e1eb04d6506add417a to your computer and use it in GitHub Desktop.
Example of mixins usage.
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
type Constructor <T = {}> = new(...args: any[]) => T; | |
function Timestamped <TBase extends Constructor> (Base: TBase) { | |
return class extends Base { | |
timestamp = Date.now(); | |
}; | |
} | |
function Restorable <TBase extends Constructor> (Base: TBase) { | |
return class extends Base { | |
restore() { | |
console.log('restored'); | |
} | |
} | |
} | |
class Connection { | |
status: string; | |
} | |
const RestorableConnection = Restorable(Connection); | |
const TimestampedRestorableConnection = Timestamped(RestorableConnection); | |
new TimestampedRestorableConnection().restore(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment