question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property decorator documentation is inaccurate?

See original GitHub issue

From the official docs about property decorators:

“The return value is ignored too.”

But the following example returns a new descriptor, and it works fine:

class Greeter {
  @logProperty
  greeting;
}

function logProperty(target, key): any {
    var value;

    var getter = function() {
      console.log('getter');
      return value;
    };

    var setter = function(newVal) {
      value = newVal;
    };

    return {
      get: getter,
      set: setter,
      enumerable: true,
      configurable: true
    };
}

const g = new Greeter();
const b = g.greeting;

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:7
  • Comments:8

github_iconTop GitHub Comments

1reaction
NetanelBasalcommented, Jul 14, 2019

Agree. They explain why in the docs:

"This is because there is currently no mechanism to describe an instance property when defining members of a prototype, and no way to observe or modify the initializer for a property. "

1reaction
fatcerberuscommented, Jul 14, 2019

I meant “pitfall” in the sense of being a footgun, people might not expect instance properties to get moved to the prototype just because they added a decorator 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

what is wrong with this property decorator (python) [duplicate]
I tried adding property decorators to my class but something went wrong. I got 6 errors!!! my code: class person: def __init__ (self, ......
Read more >
Documentation - Decorators - TypeScript
When the @enumerable(false) decorator is called, it modifies the enumerable property of the property descriptor. Accessor Decorators. An Accessor Decorator is ...
Read more >
Decorators - MikroORM
@Property() decorator is used to define regular entity property. All following decorators ... persist, boolean, yes, Set to false to define Shadow Property....
Read more >
Top 5 nuxt-property-decorator Code Examples - Snyk
To help you get started, we've selected a few nuxt-property-decorator examples, based on popular ways it is used in public projects. ; "ts">...
Read more >
7. Decorators — Python Tips 0.1 documentation
Docs »; 7. ... First, let's discuss how to write your own decorator. ... This allows us to access the pre-decorated function's properties...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found