Description
Describe the bug
Prior to 0.9.X getElementsByTagName
returned a properly typed collection. Now it returns a LiveNodeList
that doesn't infer element type from the search and types to (Node | undefined)[]
with Array.from()
.
As the result, in the following code, the image.getAttribute
part gives two compilation errors. THe first is given because image
can be undefined, the second one is because getAttribute
is not defined on Node
even though it actually is HTMLImageElement
.
const headerDoc = new DOMParser().parseFromString(
`<!DOCTYPE html> <html lang="en"> <body>${headHtml}</body></html>`,
'text/html',
),
images = headerDoc.getElementsByTagName('img'),
logoImage =
Array.from(images).find((image) => image.getAttribute('id') === 'logo') ??
Array.from(images).find((image) => image.getAttribute('alt') === 'Logo');
I am not sure what was the intent with the change but it completely messed us up, and I don't see a way to rewrite the code in any working way. We're staying back on 0.8.10 for now.
Expected behavior
As in 0.8.10, headerDoc.getElementsByTagName('img')
should return a property typed collection like HTMLCollectionOf<HTMLImageElement>
Runtime & Version:
xmldom version: 0.9.2 & 0.8.10
runtime version: Node v18.20.4
typescript: 5.6.2