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.

Erronous documentation for property decorators?

See original GitHub issue

At 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:open
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
stephenhcommented, Apr 23, 2018

@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.

0reactions
mhegazycommented, Apr 23, 2018

it has been on my list for a while now. i should file an issue for that and link different issues to it.

Read more comments on GitHub >

github_iconTop 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 >

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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found