Reputation: 4057
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.
Upvotes: 0
Views: 131
Reputation: 51
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}
*/
Upvotes: 1