Erronous documentation for property decorators?
See original GitHub issueAt https://www.typescriptlang.org/docs/handbook/decorators.html
…it reads under “Property Decorators”
If the property decorator returns a value, it will be used as the Property Descriptor for the member.
NOTE The return value is ignored if your script target is less than ES5.
I’m running a simple example with target ES6
function MyPropDesc() {
return function (targetProto: Object, propName: string | symbol) {
return {
get: function() { console.log('in getter') }
}
}
}
class SomeClass {
@MyPropDesc()
someMember;
}
However, this doesn’t seem to work. Also, when debugging this, my property decorator is being called from Reflect.js’s DecoratePropertyWithoutDescriptor
which ignores the result from the descriptor. And…typescript requires the decorator to return void
or any
. Documentation mistake?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
TypeScript: get wrong object when use Property Decorator
The TypeScript documentation says that instance property decorators receive the class prototype as the first argument.
Read more >Documentation - Decorators - TypeScript
A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use...
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 >@prop | typegoose
Decorators ; @prop ... For more information see the mongoose documentation ... Set it to false , if you want to retrieve data...
Read more >Swagger documentation - Flask-RESTX - Read the Docs
You can configure the documentation using the @api.doc() decorator. ... disabled @api.expect(resource_fields, validate=False) def post(self): pass.
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
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mhegazy ah sure, I knew about TS’s “wait for stage 3” stance, which I think makes sense.
I guess it might be getting ahead of things, but a placeholder “Support ESnext decorators once they’re stage 3” issue might be nice for others like me that were wondering about this (e.g. I looked through the open “Domain: decorators” issues and didn’t see anything). Perhaps it’s obvious though.
Also, thanks for the Object.defineProperty hint, using that in the property decorator lets me do exactly what I need in current TS.
it has been on my list for a while now. i should file an issue for that and link different issues to it.