简体   繁体   English

不返回分配-何时禁用

[英]no-return-assign - when to disable

I am trying to pass ids in this object array: 我正在尝试在此对象数组中传递ID:

const children = [{name: Jack, age: 8}, {name: Joe, age: 6}];
children.forEach((child) => (child.id = v4()));

I keep getting eslint error no-return-assign this is really bugging me (pun intended) 我不断收到eslint error no-return-assign这确实让我烦恼(双关语)

I tried: 我试过了:

children.forEach(child => child.id = v4());

children.forEach((child) => (child.id = v4())); 

children.forEach(child => (child.id = v4()));

children.forEach((child) => {
    return child.id = v4()
});

None work. 没有工作。

Should I disable eslint? 我应该禁用eslint吗? Is there a workaround? 有解决方法吗?

Well don't return anything from your callback function. 好吧,不要从回调函数返回任何东西。 Just write 写吧

children.forEach(child => {
    child.id = v4();
});

or even simpler 甚至更简单

for (const child of children) {
    child.id = v4();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 映射对象值时不返回分配 - no-return-assign when mapping over object values no-return-assign / no-unused-expressions - no-return-assign / no-unused-expressions 箭头函数不应返回赋值no-return-assign - Arrow function should not return assignment no-return-assign “不归还分配”-带括号和不带括号的赋值之间的区别 - The “no-return-assign” - Difference between Assignment with and without Parentheses React 代码中的 ESLint no-return-assign 和 no-param-reassign 错误 - ESLint no-return-assign and no-param-reassign error in React code 如何使用ESlint解决警告:在return语句中禁止分配(no-return-assign)? - How to resolve warning with ESlint: Disallow Assignment in return Statement (no-return-assign)? 如何为以下代码行修复Es-lint“ no-return-assign” - how to fix Es-lint “no-return-assign” for the following line of code 获取filteredArray.forEach((x) => (x.order -= 1)的不返回分配lint错误 - Getting no-return-assign lint error for filteredArray.forEach((x) => (x.order -= 1) 减少函数返回的分配会引发错误(ESLint问题:no-return-assign) - Reduce function returning assignment is throwing error (ESLint issue: no-return-assign) 什么时候Object.assign返回false - When will Object.assign return false
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM