Skip to content

Instantly share code, notes, and snippets.

@arlindosilvaneto
Last active May 7, 2019 21:16
Show Gist options
  • Save arlindosilvaneto/ed9b5443cf1ca1e604b130597c0adf41 to your computer and use it in GitHub Desktop.
Save arlindosilvaneto/ed9b5443cf1ca1e604b130597c0adf41 to your computer and use it in GitHub Desktop.
Typescript Decorators
function log(target: any, property: string, descriptor: PropertyDescriptor) {
let method = descriptor.value;
descriptor.value = function() {
console.warn(`[RUNNING]: ${property}`);
method.apply(this, arguments);
}
}
class Handlers {
@log
static handler(_: any, res: any): void {
res.send("Hello ts-node!");
}
}
{
"compilerOptions": {
"experimentalDecorators": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment