Created
February 6, 2023 15:24
-
-
Save Abhinav1217/401cce043924c6f0ca8564f1607de750 to your computer and use it in GitHub Desktop.
General purpose "decorater" template for Typescript 5
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
/** Taken from Andrew Burgess YT video */ | |
// https://www.youtube.com/watch?v=_1mQ_A7fq-g | |
function logged< | |
This, | |
Args extends any[], | |
Return, | |
Fn extends (this: This, ...args:Args) => Returns> | |
( | |
target: Fn, | |
context: ClassMethodDecoratorContext<This, Fn> | |
) { | |
const methodName = String(context.name); | |
function replacementMethod(this: This, ...args:Args) : Return { | |
console.log("custom decorator method"); | |
const result = target.call(this, ...args); | |
return result; | |
} | |
return replacementMethod; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment