You just need to do this:
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 apply a more specific element:
(nodes[i] as HTMLAnchorElement).style.backgroundColor = 'red';
The fact is that document.querySelectorAll returns the most general type of element, but if you know yourself what a particular type is, then you can use it because you "know better" than the compiler.
source share