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

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

typscript 使用 for  of 对节点list 进行遍历时报错: 

Type 'NodeListOf' 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"

    ],                     

 

你可能感兴趣的:(typescript)