我的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();
^^^^
我以为我在“功能Github Wiki titled 'Types in the Closure Type System'类型”部分找到了this
的答案,但这似乎没有做我认为它做的事情。
如何为Closure Compiler指定this
的类型?
感谢@RandyCasburn的评论
/** function(this:Element) */
应更改为** @this {Element} */
,以基本上将函数的上下文类型转换为Element
我认为应该使用/** function(this:Element) */
来定义具有元素上下文的函数的参数类型