Decorators
Decorators
Section titled “Decorators”function log(target: any, key: string, desc: PropertyDescriptor) { const orig = desc.value; desc.value = function (...args: any[]) { console.log(`call ${key}`, args); return orig.apply(this, args); };}
class Svc { @log run(x: number) { return x * 2 }}Notes
- Requires
"experimentalDecorators": trueprior to TS 5; standardized in TS 5.