Property decorator documentation is inaccurate?
See original GitHub issueFrom 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:
- Created 4 years ago
- Reactions:7
- Comments:8
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
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. "
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 😉