An example of a TypeScript Method Decorator, also known as an "annotation" in other languages.
You can use a decorator like @Decorator
on a method inside of a class
.
export function Decorator <Args extends any[], Result extends any> (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: Args) => Result>) {
const originalMethod = descriptor.value // save a reference to the original method
// NOTE: Do not use arrow syntax here. Use a function expression in
// order to use the correct value of `this` in this method (see notes below)
if (originalMethod) {