Created
May 5, 2020 13:56
-
-
Save fukata/61be3c41d186741a5cdbfc76a89d423a to your computer and use it in GitHub Desktop.
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
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