Skip to content

Instantly share code, notes, and snippets.

@nhh
Created July 26, 2018 06:58
Show Gist options
  • Save nhh/c6f2c717659cad87fcf358931d48df8c to your computer and use it in GitHub Desktop.
Save nhh/c6f2c717659cad87fcf358931d48df8c to your computer and use it in GitHub Desktop.
Typescript method decorator
export default function log(targetObject: Object, targetMethodName: string | symbol, targetMethod: TypedPropertyDescriptor<Function>) {
return {
value: function( ... args: any[]) {
if(targetMethod.value) {
const result = targetMethod.value.apply(targetObject, args);
return result + 1;
}
}
}
}
class Calculator {
@log
add(x: number, y: number) {
return x + y;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment