提问人:miken32 提问时间:6/1/2021 最后编辑:LazyOnemiken32 更新时间:6/1/2021 访问量:364
键入 PhpStorm 的 jQuery 方法
Typehinting jQuery methods for PhpStorm
问:
我遇到了与这个问题相同的问题,但我使用的是 JavaScript,而不是 TypeScript,因此那里的解决方案不适用。
使用以下代码:
$("input").each(function(i, el) {
console.log(el.value);
});
我收到关于以下内容的投诉:el.value
未解析的变量值
这是因为 jQuery 类型提示为 但该属性仅存在于某些子类上,例如 。el
HTMLElement
value
HTMLInputElement
我发现使此警告安静的唯一方法是这样的,我并不是为了一个小警告而疯狂地这样做(在某些情况下,它会产生另一个关于“冗余变量”的警告):
$("input").each(function(i, el) {
/** @type {HTMLInputElement} */
const input = el;
console.log(input.value);
});
有没有更干净的方法来解决这个问题?我确实尝试了这样的内联类型定义,但没有任何运气:
$("input").each(function(i, /** @type {HTMLInputElement} */el) {
console.log(el.value);
});
下面是其中每个在 IDE 中的外观:
答: 暂无答案
评论
@param
@type
el