我使用 PhpStorm,当我使用 JSDoc 将参数定义为 jQuery 类型时,它会发出警告。
我尝试将 jQuery 配置为库,但似乎不起作用。
这是我的代码:
/**
* @param {jQuery} $button
*/
function setActive($button)
{
// The code is working fine, but PhpStorm is giving the warning
// "Unresolved function or method addClass()" here.
$button.addClass("active");
// If I try to do this, no warning is displayed.
$("#test").addClass("test");
}
编辑:
一些方法出现在智能感知中(我不确定为什么),但不幸的是 addClass
不是其中之一。
最佳答案
尝试添加 JQuery 类型(通过设置 | 语言和框架 | JavaScript | 库、TypeScript 社区 stub 或运行 npm i @types/jquery
在项目目录中) - 这应该可以解决问题:
关于jquery - 带有 jQuery 参数的 PhpStorm 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47885291/