如何修复ESLint错误使用数组解构

Arv*_*aha 3 javascript eslint

我的代码中有一行:

this.someVar = document.querySelectorAll("div[container-type='some-container']")[0];
Run Code Online (Sandbox Code Playgroud)

ESLint检查为此行“使用数组解构”抛出错误。如何解决此错误。

Tar*_*sam 8

尝试这个

([this.someVar] = document.querySelectorAll("div[container-type='some-container']"));
Run Code Online (Sandbox Code Playgroud)

  • 添加了括号以明确表示它的一个表达式,虽然省略了它们在此处的工作原理,但不适用于对象解构,`{0:someVar} = [...]`将是语法错误。但是,如果您愿意,可以随时回滚/忽略它们。 (2认同)