Angular 2.4.4、TypeScript 2.1.5、PhpStorm 2017.2.1 我写这段代码:
const list = document.querySelectorAll('path.frame-zone');
list.forEach(() => {
但是第二行带有红线下划线并且 TsLint 报告“类型 NodeListOf 上不存在 forEach 属性”
但是当我 ctrl+click forEach
它让我到lib.es6.d.ts
其中 forEach
声明为 interface NodeListOf<TNode extends Node>
为什么它不让我使用它?怎么了?
最佳答案
您需要将其转换为数组:
const frameZones = Array.from(document.querySelectorAll('path.frame-zone'));
frameZones.forEach((...) => {});
关于angular - NodeListOf 类型上不存在 forEach 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46349147/