I am trying to pass a method to a typescript decorator. I am able to do so when I do this as an inline arrow function. But I am not able to do this in the following way:
function preProcessor(preFn:any) {
return function (
target: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {
descriptor.value = function (param:any) {
return preFn(param);
}
};
}
class C {
@preProcessor(this.capitalize)
methodA(str: any) {
console.log(str) }
capitalize = (x:any)=>{return x.toUpperCase()}
}
var c = new C()
console.log(c.methodA("samurai..."))
This works:
@preProcessor((x:any)=>{return x.toUpperCase()})