Web API has Element interface which extends Node interface. How to tell JetBrains IDE that this particular Node is Element?
Hope the code below explains everything.
/** * @param {Node} node * @return {string} */ function extractor(node) { let text; if (node.nodeType === Node.ELEMENT_NODE) { // On the next line IDE shows a warning, // that innerHTML property is not defined for Node. // How to tell IDE that node variable became and Element here? text = node.innerHTML; } else { text = node.textContent; } return text; }
I'm using PyCharm Professional, but I don't think it matters.
You can't.
If you do want, you can use Typescript instead.
text = (node as Element).innerHTML;
But in javascript, there is no strict types, you can only try:
/** * @param {Node | Element} node * @return {string} */
1.4m articles
1.4m replys
5 comments
57.0k users