当前位置: 代码迷 >> 综合 >> typescript Type 'NodeListOfany' must have a '[Symbol.iterator]()' method that returns an iterato
  详细解决方案

typescript Type 'NodeListOfany' must have a '[Symbol.iterator]()' method that returns an iterato

热度:76   发布时间:2024-01-21 08:47:53.0
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"],                     

 

  相关解决方案