Skip to content

Instantly share code, notes, and snippets.

@Klerith
Last active May 14, 2024 23:39
Show Gist options
  • Save Klerith/c4bd6ddc72362ac35b68a0727294ebdc to your computer and use it in GitHub Desktop.
Save Klerith/c4bd6ddc72362ac35b68a0727294ebdc to your computer and use it in GitHub Desktop.
Deprecated Method - Decorador

@Deprecated - Method Decorator

En la definición del método, se puede marcar como obsoleto (deprecated) con la justificación. Esto ayudará a que otros developers sepán que deben de utilizar ya la alternativa.

@Deprecated('Most use speak2 method instead')
 speak() {
      console.log(`${ this.name }, ${ this.name }!`)
 }
const Deprecated = (deprecationReason: string) => {
return (target: any, memberName: string, propertyDescriptor: PropertyDescriptor) => {
// console.log({target})
return {
get() {
const wrapperFn = (...args: any[]) => {
console.warn(`Method ${ memberName } is deprecated with reason: ${ deprecationReason }`);
//! Llamar la función propiamente con sus argumentos
propertyDescriptor.value.apply(this, args);
}
return wrapperFn;
}
}
}
}
@Googluu
Copy link

Googluu commented Nov 30, 2023

de lo mejor

@Googluu
Copy link

Googluu commented Nov 30, 2023

nice

@MaxC26
Copy link

MaxC26 commented Feb 16, 2024

Thanks!

@Savecoders
Copy link

Gracias

@balfaz
Copy link

balfaz commented Apr 18, 2024

👍

@lmendoza27
Copy link

Excelente, gracias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment