Last active
April 30, 2023 21:07
-
-
Save christopherbauer/21bb4fc674ca52193b37f3235c0e2540 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* An example decorator that takes no arguments | |
* @param originalMethod The target method to decorate | |
* @param _context The context type, can be one of ClassMemberDecoratorContext | ClassMethodDecoratorContext | ClassGetterDecoratorContext | ClassSetterDecoratorContext | ClassFieldDecoratorContext | ClassAccessorDecoratorContext. Try the Command+F12 shortcut to look at the documentation! | |
* @returns A function that runs the original method but does some other fun stuff! | |
*/ | |
const MyDecorator = ( | |
originalMethod: Function, | |
_context: ClassMethodDecoratorContext | |
) => { | |
function ReplacementMethod(this: any, ...args: any[]) { | |
const result = originalMethod.call(this, ...args); | |
return result; | |
} | |
return ReplacementMethod; | |
}; | |
class Typescripter { | |
@MyDecorator | |
writeTypeyCode() { | |
return true; | |
} | |
@MyDecorator | |
writeTypeyCodeWithArgs(amount: number) { | |
return amount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment