简体   繁体   English

如何告诉 JetBrains IDE 这个 javascript 变量将类型更改为另一个?

[英]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.

相关问题 如何判断JavaScript变量是否是对另一个变量的引用 - How to tell if a JavaScript variable is a reference to another variable JetBrains IDE 上的 Javascript:类型提示自主自定义元素实例 - Javascript on JetBrains IDE: type-hinting the autonomous custom element instance 如何分辨JavaScript和/或jQuery对象的类型 - How to tell the type of a JavaScript and/or jQueryobject 如何判断javascript变量是否为函数 - how to tell if a javascript variable is a function JetBrains WebStorm中的JavaScript变色 - JavaScript variable color in JetBrains WebStorm JetBrains IDE 上的 Javascript:将基类类型提示的实例分配给类型提示的参数作为子类 - Javascript on JetBrains IDE: assigning the base class type-hinted instance to the parameter type-hinted as a sub-class 如何判断 HTML textarea 何时被 Javascript 更改 - How to tell when an HTML textarea has been changed by Javascript 如何告诉JavaScript我的变量是数组而不是字符串? - How to tell JavaScript that my variable is an array and not a string? javascript 如何判断一个数字是否是另一个数字的倍数 - javascript how to tell if one number is a multiple of another 如何告诉纯 javascript 不断检查变量? - How to tell pure javascript to to constantly check a variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM