如何在带有ESLint @ typescript-eslint / no-explicit-any的NodeList上使用“ for of”?

如果我想循环一个NodeList,例如这样的话:

const links = document.querySelectorAll('a');
for(const link of links) {
   // loop code
}

Typescript给出错误:
TS2495: Type 'NodeListOf<Element>' is not an array type or a string type.

一种解决方法是使用:
for(const link of links as any as Element[]) {

但这会触发ESLint规则:
@typescript-eslint/no-explicit-any

有没有一种方法可以在Typescript中循环NodeList,而又不会触发no-explicit-any?

yjukhdxfv 回答:如何在带有ESLint @ typescript-eslint / no-explicit-any的NodeList上使用“ for of”?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3156415.html

大家都在问