將函數添加到實際已存在的typescript的最佳方式是什麼?在我的情況下,這是Node.getAttribute()
,它實際上內置於瀏覽器,但尚未被TypeScript識別。它的錯誤:Cannot find property 'getAttribute' on type 'Node'.
在TypeScript中添加現有函數:Node.getAttribute()
在我來說,我就遇到了這個錯誤執行以下:
var xmlDocument = new DOMParser().parseFromString(xmlString, "text/xml"),
rootfile = xmlDocument.getElementsByTagName("aNode")[0];
console.log(rootfile.getAttribute("anAttribute"));
這成功的瀏覽器,但通過打字稿拋出一個錯誤。
我會努力。但是,當我修改* lib.d.ts *與相同的指令沒有任何反應...... – Roger
您正在修改的'lib.d.ts'不一定是您的開發工具所使用的。 – basarat