[英]How to fix Eslint prefer-destructuring
我应该如何重写以下行,以避免出现此错误
ctrl.formData.type = ctrl.types[0];
Tweaking the rule configuration based on the prefer-destructuring docs ought to avoid this case. 根据“ preferred-destructuring”文档调整规则配置应避免这种情况。 This change would disable the rule for assignments like your example while keeping it for the more common case of declarations:
此更改将禁用分配规则(如您的示例),同时保留更常见的声明用例:
"prefer-destructuring": ["error", {
"AssignmentExpression": {
"array": false,
"object": false
}
}]
If you want to keep the rule configured as-is, this one-liner works: 如果您想按原样配置规则,则此一线工作:
[ctrl.formData.type] = ctrl.types;
This should work: 这应该工作:
let [ type ] = ctrl.types;
ctrl.formData.type = type;
More info here: https://eslint.org/docs/rules/prefer-destructuring 此处提供更多信息: https : //eslint.org/docs/rules/prefer-destructuring
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.