2017-09-21 60 views
3

角2.4.4,2.1.5打字稿,PhpStorm 2017年2月1日 我写这篇文章的代码的forEach上不存在类型:财产NodeListOf

const list = document.querySelectorAll('path.frame-zone'); 
list.forEach(() => { 

但第二行强调用红色线及TsLint报道说 “属性的forEach不上型NodeListOf存在”但是,当我按Ctrl +单击它让我的forEachlib.es6.d.ts其中forEach声明为interface NodeListOf<TNode extends Node>

为什么它不会让我使用它呢?哪里不对?

+0

您正在使用什么LIB?是es6还是使用旧版本? –

+0

在这种情况下lib是什么?我正在维护另一个团队的旧项目。也许有些配置错误,但不知道在哪里看。您的tsconfig.json中的 – Gherman

+0

。你的项目使用什么库? –

回答

5

你需要将其转换为一个数组:

const frameZones = Array.from(document.querySelectorAll('path.frame-zone')); 
frameZones.forEach((...) => {}); 
+0

是否正确,至少在实际上有帮助。我不确定。现实中的问题仍然存在。为什么PhpStorm声称它有这种方法? – Gherman

0

尝试投它:

const list = (NodeListOf) document.querySelectorAll('path.frame-zone'); 

啊打字稿也许是这样的:

const list = <NodeListOf> document.querySelectorAll('path.frame-zone'); 
+0

我试过了。它没有帮助。林特已经知道它是什么类型。 – Gherman

+0

键入其NodeListOf或NodeList!? – Mars

+0

It's NodeListOf – Gherman