如何使用 Closure Compiler 在函数中定义 "this" 的类型

How to define type of "this" in function with Closure Compiler

我的项目使用 Closure Compiler 的目标是实现 100% 类型化,但我正在努力使用一个简单的 jQuery 模式,如下所示:

$Controls.on('change input', /** function(this:Element) */ function () {
    $(this).removeClass('is-invalid').next('.invalid-feedback').remove();
});

有或没有评论 /** function(this:Element) */,我收到以下错误:

js/quote.js:61: WARNING - could not determine the type of this expression
        $(this).removeClass('is-invalid').next('.invalid-feedback').remove();
          ^^^^

我以为我在 "Function this Type" 部分找到了 Github Wiki titled 'Types in the Closure Type System' 的答案,但这似乎并没有像我想的那样。

如何为 Closure Compiler 指定 this 的类型?

感谢@RandyCasburn 的评论

/** function(this:Element) */ 应更改为 ** @this {Element} */ 以实质上将函数上下文的类型转换为 Element

我认为应该使用 /** function(this:Element) */ 来定义具有元素上下文的函数的参数类型