NetanelBasal / helpful-decorators

Helpful decorators for typescript projects

Home Page:https://netbasal.com/create-and-test-decorators-in-javascript-85e8d5cf879c

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decorated method returns nothing

Ledzz opened this issue · comments

commented

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

Current behavior

Method decorated with @measure returns nothing. Haven't tested with other decorators.

Expected behavior

Returned value does not change

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/typescript-okyls9

The issue is here:

  descriptor.value = function(...args) {
    const start = performance.now();
    originalMethod.apply(this, args);
    const end = performance.now();
    console.log(`Call to ${propertyKey} took ${(end - start).toFixed(2)} milliseconds.`);
  };

It should be:

  descriptor.value = function(...args) {
    const start = performance.now();
    const result = originalMethod.apply(this, args);
    const end = performance.now();
    console.log(`Call to ${propertyKey} took ${(end - start).toFixed(2)} milliseconds.`);
    return result;
  };

Do you want to create a PR?

commented

yes, I'll do it today :)