Skip to content

Instantly share code, notes, and snippets.

@FFKL
Created January 16, 2020 19:18
Show Gist options
  • Save FFKL/34d552a1d3c285e1eb04d6506add417a to your computer and use it in GitHub Desktop.
Save FFKL/34d552a1d3c285e1eb04d6506add417a to your computer and use it in GitHub Desktop.
Example of mixins usage.
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