[英]How to tell to JetBrains IDE that this javascript variable changed type to another?
Web API has Element interface which extends Node interface. Web API 具有扩展Node接口的Element接口。 How to tell JetBrains IDE that this particular Node is Element?
如何告诉 JetBrains IDE 这个特定节点是 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.我正在使用 PyCharm Professional,但我认为这并不重要。
You can't.你不能。
If you do want, you can use Typescript instead.如果你愿意,你可以使用 Typescript 代替。
text = (node as Element).innerHTML;
But in javascript, there is no strict types, you can only try:但是在javascript中,没有严格的类型,只能试试:
/**
* @param {Node | Element} node
* @return {string}
*/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.