ESLint unexpected character '@' for JS decorators

前端 未结 3 728
无人共我
无人共我 2021-01-11 11:27

I\'m trying to use decorators in my JS project, however ESLint is throwing an error stating that the @ symbol is a unexpected character.

My code:

@o         


        
相关标签:
3条回答
  • 2021-01-11 11:53

    If you using Visual Code it will not always work. You need to add into User Settings (or Workspace Settings) following parameter: { ... "eslint.options": { "experimentalDecorators": true } ... }
    Somehow this option wins anything you put into .eslintrc .

    0 讨论(0)
  • 2021-01-11 11:56

    You probably want to use babel-eslint which uses Babel to parse things that ESLint hasn't implemented yet (usually experimental features like this). From their README:

    At the moment, you'll need it if you use stuff like class properties, decorators, types.

    It is used with your current eslint setup, you just have to update some configuration in your .eslintrc

    0 讨论(0)
  • 2021-01-11 12:11

    A quick answer:

    Install a lib

    npm i -D babel-eslint
    

    Add to your .eslintrc

    "parser": "babel-eslint"
    
    0 讨论(0)
提交回复
热议问题