我正在使用TypeScript,並且在正確輸入所有變量(特別是節點和元素類型)時出現很多問題。TypeScript typecast對象節點到對象元素
var pageLst:NodeList = document.querySelectorAll('.aClassName'); var el:Element = pageLst.item(i) as Element; // gives an TypeScript error TS1005: ';' experted >> after the 'i)' and/or 'as'.
'pageLst.item(I)' 返回一個節點,被視爲 '作爲' 元素。 Typescript編輯器不會給出警告。只有在轉換代碼時,纔會生成錯誤。
而且我認爲這也應該工作;
var el:Element = pageLst.item(i);
由於元是基於一個節點。
對此問題的任何見解或僅使用< Element> pageLst.item(i)解決方案。
發佈實際的錯誤消息。 –