Type 'NodeListOf<any>' must have a '[Symbol.iterator]()' method that returns an iterator.
typscript 使用 for of 对节点list 进行遍历时报错:
Type 'NodeListOf<any>' must have a '[Symbol.iterator]()' method that returns an iterator.
比如下面代码
let items = document.querySelectorAll('div');
for(let v of items ) {
console.log(v);
}
【解决方法】
重新配置 项目下的 ts 配置文件 tsconfig.json,添加一条 dom.iterable 并【重新启动项目】
"compilerOptions": {
/* Basic Options */
"target": "ES2016",
"module": "ESNext",
"lib": [
"dom",
"dom.iterable",//这里是新增项
"es2016"
],