最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Expected parentheses around arrow function argument. (arrow-parens) - Stack Overflow

programmeradmin4浏览0评论

How to avoid Flow-type error on an ES7 arrow function

handleSelectCategory = (e) => {
  const { form } = this.state;

  let newCategories = [];
  if (form.categories.findIndex((c) => c.value === e.value) >= 0) {
    newCategories = form.categories.filter((c) => c.value !== e.value);
  } else {
    newCategories = [...form.categories, e];
  }
  this.setState({
    form: Object.assign({}, form, { categories: newCategories }),
  });
};

I receive the warning

Expected parentheses around arrow function argument. (arrow-parens)

How to avoid Flow-type error on an ES7 arrow function

handleSelectCategory = (e) => {
  const { form } = this.state;

  let newCategories = [];
  if (form.categories.findIndex((c) => c.value === e.value) >= 0) {
    newCategories = form.categories.filter((c) => c.value !== e.value);
  } else {
    newCategories = [...form.categories, e];
  }
  this.setState({
    form: Object.assign({}, form, { categories: newCategories }),
  });
};

I receive the warning

Expected parentheses around arrow function argument. (arrow-parens)
Share Improve this question edited Jun 25, 2021 at 8:01 thelovekesh 1,4521 gold badge9 silver badges22 bronze badges asked Sep 15, 2018 at 13:41 aliali 1511 gold badge2 silver badges5 bronze badges 2
  • 6 It's not a type error, it's a linter warning. Have you considered reading its documentation? – Bergi Commented Sep 15, 2018 at 13:49
  • same , but i looking for the configuration . my .eslintrc.js 'arrow-parens': ['error', 'as-needed'], on vscode – Yogi Arif Widodo Commented Oct 26, 2022 at 22:43
Add a comment  | 

1 Answer 1

Reset to default 17

Parentheses around the parameter to an arrow function are optional in ES6 when there's only one argument, but ESLint complains about this by default. This is controlled by the arrow-parens option.

Either change this option, or change your arrow functions to use (c) instead of c as the parameter lists.

发布评论

评论列表(0)

  1. 暂无评论