If you write below code:
const e = document.body.firstChild;
if (e.nodeType === Node.TEXT_NODE)
console.log(e.data);
You will get this error on e.data
:
TS2339: Property 'data' does not exist on type 'ChildNode'.
While if the condition be true (e.nodeType === Node.TEXT_NODE
) then e
has some other properties in addition to regular ChildNode
properties, like data
and wholeText
.
What type should I cast to (other than any
)?