// *** before: ***
//experimental decorators (experimentalDecorators: true) are not the TC39
//standard:
// a shape of their own, at odds with the coming runtime
function logged(target: any, propertyKey: string,
descriptor: PropertyDescriptor) {
const original = descriptor.value;
descriptor.value = function (...args: any[]) {
console.log(`calling ${propertyKey}`);
return original.apply(this, args);
};
}
class Service {
@logged
run() {}
}
// *** in version 5.0: ***
// decorators as TC39 standardised them, with no experimental flag
function loggedStd<This, Args extends any[], Return>(
target: (this: This, ...args: Args) => Return,
context: ClassMethodDecoratorContext
) {
return function (this: This, ...args: Args): Return {
console.log(`calling ${String(context.name)}`);
return target.call(this, ...args);
};
}
class ServiceStd {
@loggedStd
run() {}
}