Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by kobako for Typescript method is return undefined with method decorator

OMG, I thought your problem is the same with me but it's not.

The problem is just caused by that you return nothing when re-define the function.

Here is your original code block:

descriptor.value = function (...args:any[]) {        //before        console.log(`${key} method called with args: ${JSON.stringify(args)}`);        let result = originalMethod.apply(this, args);        //after        console.log(`${key} method return value: ${JSON.stringify(result)}`);    }

Now, return it and it will work correctly.

descriptor.value = function (...args:any[]) {        //...        let result = originalMethod.apply(this, args);        //...        return result; //ADD HERE!!!    }

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>