Skip to content

Instantly share code, notes, and snippets.

@Abhinav1217
Created February 6, 2023 15:24
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 Abhinav1217/401cce043924c6f0ca8564f1607de750 to your computer and use it in GitHub Desktop.
Save Abhinav1217/401cce043924c6f0ca8564f1607de750 to your computer and use it in GitHub Desktop.
General purpose "decorater" template for Typescript 5
/** 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