Issue
For some reason when I use a decorator on a get accessor (as shown below), I pass compilation, but always end up with a runtime error message saying:
Uncaught TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute
Why does this happen and how can I overcome it? To note: I am only using a getter and not a setter.
Example Code:
class ThingBox {
private things = [1,2,3,4,5]
@MyDecorator
get totalTings(): number { return this.things.length }
}
Solution
You have set a get
method and value
in the descriptor, but this is invalid (you can have accessors or value, not both). In your case, you need to patch the get
method inside of the decorator instead of value.
Answered By - izmaylovdev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.