如何配置 ESLint 以使用例如event.target 和 element.parentNode?

How to configure ESLint for using e.g. event.target and element.parentNode?

编辑: 我没有意识到错误消息甚至不是来自 ESLint,而是来自 Visual Studio 代码中称为 [js] 的东西。我会删除这个问题,但它可能会帮助其他人也将 [js] 输出误认为是 ESLint。仍然很想知道这个 [js] 是个什么样的过程。

我接到了定义项目范围的 .eslintrc.js 文件的任务,以确保团队的代码符合通用标准。

运行 使用预设 eslint:recommended 的 ESLint 给我以下错误消息

The property "parentNode" does not exist for the type "EventTarget".

这是有问题的代码段:

window.addEventListener('keydown', event => {
  const currentTag = event.target.parentNode.tagName;
  /* ... */
})

我知道可以有 event.target 而不是 HTMLElement 但我应该如何编码 -或配置 ESLint - 所以这一行不再产生 ESLint 错误?只要 ESLint 报告任何错误,我们就计划让构建失败,因此必须 解决这个问题。

导致类似错误的第二行代码:

document.activeElement.click();

导致 ESLint 错误

The property "click" does not exist for the type "Element".

第三个例子:

const rows = this.childNodes[1].querySelectorAll('tr');

抛出

The property "querySelectorAll" does not exist for the type "Node & ChildNode".

注意:请不要建议使用flow或Typescript,代码将保持纯ES6(我理解ESLint是为了)。

根据 OP,代码包含 // @ts-check 作为第一行

因此很明显这与单独的eslint无关,而是由内部引起的VSCode linter

The easiest way to enable type checking in a JavaScript file is by adding // @ts-check to the top of a file.