諸事情によりメソッド名を変更すると壊れるアプリケーションのためのメソッド名変更禁止Docorator
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
function StaffAction(args: { nameMustBe: string }) { | |
return (target: any, name: string, descriptor: PropertyDescriptor) => { | |
if (args.nameMustBe !== name) { | |
throw new Error(` | |
!!! FATAL: ${name}() !!! | |
Fixed method name has changed. This change will breake application. | |
Please revert the method name to "${args.nameMustBe}". | |
`); | |
} | |
}; | |
} | |
class FixedMethods { | |
constructor() { | |
} | |
@StaffAction({ nameMustBe: "correctName" }) | |
correctName() { | |
return; | |
} | |
@StaffAction({ nameMustBe: "mustBeName" }) | |
invalidName() { | |
return; | |
} | |
} | |
const fixed = new FixedMethods(); | |
// No error | |
fixed.correctName(); | |
// Must throw error | |
fixed.invalidName(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
transpiled js