Skip to content

Instantly share code, notes, and snippets.

@fukata
Created May 5, 2020 13:56
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 fukata/61be3c41d186741a5cdbfc76a89d423a to your computer and use it in GitHub Desktop.
Save fukata/61be3c41d186741a5cdbfc76a89d423a to your computer and use it in GitHub Desktop.
export default null // モジュールモードを強制します
class User {
constructor (
private name: string
) {}
getDebugValue() {
return {
name: this.name
}
}
}
type DebuggableClassConstructor = {
new(...args: any[]): {getDebugValue(): object}
}
function withDebug<C extends DebuggableClassConstructor>(Class: C) {
return class extends Class {
debug() {
console.log(this.getDebugValue())
}
}
}
let user = new (withDebug(User))('fukata')
user.debug()
// $./node_modules/.bin/ts-node mixin.ts
// { name: 'fukata' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment