I have found similar questions, but most of them seem to focus on this
and usually not purely typescript. However, I have a MINIMAL RUNNABLE EXAMPLE , that I just can’t find an answer to.
I’m not understanding why the originalMethod.apply(this, args)
seems to log undefined
for it’s parameters. Some suggest circular references, while other suggest using target, BUT, the code is so simple here, that there are no circular references I see and yes I did use target as well (RUNNABLE CODE), yet the result’s the same. I have even avoided using arrow function
Does the originalMethod.apply
not pass on the parameters? Why is the method body printing undefined for it’s supplied parameters? Is this a typescript bug?:
function ValidateInputParams() {
return function (target: any, key: any, descriptor: any) {
const originalMethod = descriptor.value;
console.log('original method descriptor: ', originalMethod);
descriptor.value = function (request: any) {
const inputBody = request.body;
const inputParams = request.params;
console.log(inputBody, inputParams)
console.log('Inside the descriptor', request.body);
return originalMethod.apply(this, request); // supplying target also not working
};
};
}
class MyClass {
@ValidateInputParams()
myWork(request: any) {
console.log('REQUEST INSIDE MYCLASS',request)
return;
}
}
new MyClass().myWork({body: 'Test body method'})