You just need to cast it:
let nodes = document.querySelectorAll('a');
for (let i = 0; nodes[i]; i++) {
let node = nodes[i];
var c = (nodes[i] as HTMLElement).style.backgroundColor = 'red';
}
You can even cast to a more specific element:
(nodes[i] as HTMLAnchorElement).style.backgroundColor = 'red';
The thing is that document.querySelectorAll
returns the most generic element type, but if you know yourself what is the specific type then you can cast, because you "know better" than the compiler.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…