Typescript Decorator Blueprint

JS
S
JavaScript

Reusable template for creating TypeScript decorators, streamlining implementation of metadata annotations and behavior modification for classes, methods, and properties.

1/* First define the decorator
2  target is the class on which you apply the decorator, or the class of the method on which you apply the decorator.
3  key is the property name of the specific property you are applying the decorator to.
4  descriptor is the descriptor of the property.
5*/
6export function Dummy(params: any[]) {
7  return function validator (target: any, key: any, descriptor: any) {
8    const fn = descriptor.value;
9    descriptor.value = (...args: any) => {
10      return fn.apply(this, args);
11    }
12  }
13}

Created on 10/1/2021