0

I am getting a weird eslint error when using the spread operator a certain way. I am using it all over my application, but this one line is throwing an error

//this is ok
const sortById = arr => [...arr].sort((a, b) => (parseInt(a.EMPLOYEE_ID) < parseInt(b.EMPLOYEE_ID) ? -1 : 1));

//this is ok
const addStoreType = arr => arr.map(obj => ({ ...obj, STORE_TYPE: typeOfStore(parseInt(obj.DEPARTMENT_NBR))}));

//throws error
const reduceData = arr => arr.map(({ SEQUENCE, TEST_DATE, ADJUSTED_HIRE_DATE, ...rest }) => rest);

This is my eslint config

{
  "extends": ["plugin:prettier/recommended"],
  "parserOptions": {
    "ecmaVersion": 7,
    "sourceType": "module"
  },
  "rules": {
    "prettier/prettier": ["error", {
      "singleQuote": true
    }]
  }
}
kemotoe
  • 1,730
  • 13
  • 27

1 Answers1

2
     "ecmaVersion": 7,

The spread syntax for object literals is part of the language since ES8. It is separate from the spread syntax for array literals and function calls, which was added in ES6.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Adding to the reply, the following also worked for me. Personally I find the year easier to comprehend than the version. YMMV. ```ecmaVersion: 2018``` – shanky Sep 23 '20 at 19:29