When I use domUtils.getElementsByTagName('tagName', dom), I can pass in the dom and get the expected element. However, when I use domUtils.getElementsById('eleId', dom), TypeScript allows me to pass in the dom, but it doesn't return the correct result (null).
Upon checking the getElementsByTagName source code, I found that it first makes an isTag check on the passed parameter (dom). This causes the dom to not enter the subsequent logic because the dom tag is 'root'. This is obviously confusing, and I hope TypeScript will be more rigorous about the types of parameters passed in.
I now use domUtils.getElementsById('eleId', dom.children) as a workaround.
When I use
domUtils.getElementsByTagName('tagName', dom)
, I can pass in thedom
and get the expected element. However, when I usedomUtils.getElementsById('eleId', dom)
, TypeScript allows me to pass in thedom
, but it doesn't return the correct result (null
).Upon checking the
getElementsByTagName
source code, I found that it first makes anisTag
check on the passed parameter (dom
). This causes the dom to not enter the subsequent logic because thedom
tag is'root'
. This is obviously confusing, and I hope TypeScript will be more rigorous about the types of parameters passed in.I now use
domUtils.getElementsById('eleId', dom.children)
as a workaround.