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.

Cannot Decorate Class Properties

See original GitHub issue

When using babel-plugin-transform-class-properties any decorated class property is undefined

function myDecorator(){
    // Decorate stuff
}
...
class Person{
    @myDecorator
    age = 43; // Nope - doesn't work

    @myDecorator
    toString(){ // Yep - works
    }
    constructor(){
        console.log(this.age) // undefined
    }
}

Furthermore, the decorator is never called for the class property. Am I missing something?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
loganfsmythcommented, May 6, 2016

Same issue as https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy/issues/24, your config has transform-class-properties listed before transform-decorators-legacy, which is causing problems. Given your config, I’d do

{
    "presets": [
        "es2015",
        "stage-0"
    ],
    "plugins": [
        "babel-plugin-syntax-jsx",
        "babel-plugin-inferno",
        "babel-plugin-transform-decorators-legacy"
    ]
}

since stage-0 will cover transform-object-rest-spread and transform-class-properties for you already.

0reactions
azaruscommented, May 16, 2017

Sorry to post here but i have the same issue and I have the decorators-legacy plugin listed first.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to access value using Property decorator in typescript
A Property Descriptor is not provided as an argument to a property decorator due to how property decorators are initialized in TypeScript. This ......
Read more >
[v6] Cannot decorate ... the property is already ... - GitHub
This check fails, if the subclass only contains computed properties and no single observable variable. Modifying SubClass by adding a simple ...
Read more >
Python Property Decorator - TutorialsTeacher
Learn what is decorator and property decorator. The property decorator allow us to define properties easily without calling the property() function ...
Read more >
Documentation - Decorators - TypeScript
A property decorator cannot be used in a declaration file, or in any other ambient context (such as in a declare class). The...
Read more >
Python Property Decorator - GeeksforGeeks
Which is used to return the property attributes of a class from the stated getter, setter and deleter as parameters. Now, lets see...
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