将函数添加到实际已经存在的打字稿的最佳方法是什么?在我的例子中Node.getAttribute()
,它实际上是浏览器内置的,但尚未被 TypeScript 识别。它错误:Cannot find property 'getAttribute' on type 'Node'.
就我而言,我在执行以下操作时遇到了这个错误:
var xmlDocument = new DOMParser().parseFromString(xmlString, "text/xml"),
rootfile = xmlDocument.getElementsByTagName("aNode")[0];
console.log(rootfile.getAttribute("anAttribute"));
这在浏览器中成功,但由 TypeScript 引发错误。