Spread operator and EsLint

后端 未结 2 1295
予麋鹿
予麋鹿 2021-01-01 09:32

I want to copy object and change one of its field. Something like this:

const initialState = {
  showTagPanel: false,
};

export default function reducerFoo(         


        
相关标签:
2条回答
  • 2021-01-01 10:06

    Update as of eslint 5.0.0

    Source: https://eslint.org/docs/5.0.0/user-guide/migrating-to-5.0.0

    Add ecmaVersion: 2018 to parserOptions in your .eslintrc file.

    {
      "extends": [
        "eslint:recommended"
      ],
      "parserOptions": {
        "ecmaVersion": 2018,
        "sourceType": "module",
        "ecmaFeatures": {
          "jsx": true,
        }
      }
    }
    

    Original answer

    Add "experimentalObjectRestSpread": true to ecmaFeatures in your .eslintrc file.

    Example

    {
      "extends": [
        "eslint:recommended"
      ],
      "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module",
        "ecmaFeatures": {
          "jsx": true,
          "experimentalObjectRestSpread": true
        }
      }
    }
    
    0 讨论(0)
  • 2021-01-01 10:10

    Btw, if answered from @Alexander at 15 July 2017 not solving your problem. Please change your ecmaVersion into 2018, like this:

    ESLint ^5 or newer version
    {
      "env": {...},
      "extends": [...],
      "parserOptions": {
        "ecmaVersion": 2018, // use this.
        "ecmaFeatures": {
          "jsx": true // just use this on ecmaFeatures, no need "experimentalObjectRestSpread" anymore.
        }
      }
    }
    

    instead using "experimentalObjectRestSpread": true like this:

    This is only for ESLint under v5
    {
      "env": {...},
      "extends": [...],
      "parserOptions": {
        "ecmaVersion": 6,
        "ecmaFeatures": {
          "jsx": true,
          "experimentalObjectRestSpread": true // instead this
        }
      }
    }
    

    For complete explanation about this, you can read here -> experimentalObjectRestSpread has been DEPRECATED.

    0 讨论(0)
提交回复
热议问题