Google Closure Compiler无法识别类型注释

时间:2016-09-29 01:08:17

标签: javascript extjs google-closure-compiler

我正在尝试使用Google的Closure Compiler编译ExtJS 6.2.0。 extjs源代码中有以下注释:

* @param {Ext.data.TreeModel[]} records An array of records.

关闭错误,因为它无法识别此类注释。错误如下所示:

extjs-6.2.0/build/ext-all-debug.js:248792: ERROR - Bad type annotation. expecting a variable name in a @param tag. See https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation for more information.
     * @param {Ext.data.TreeModel[]} data.records An Array of Models representing the 

我不一定在提供的URL中看到解决方案。这样的ExtJS中还有很多类型,我猜测编译器会遇到问题。

这里有一个简单的解决方法吗?我可以从编译中删除--jscomp_error checkTypes,但我宁愿以正确的方式执行此操作。

1 个答案:

答案 0 :(得分:2)

您显示的注释与Google封闭编译器不兼容。相反它会被写成

* @param {Array<Ext.data.TreeModel>} records An array of records.

我怀疑他们正在使用JSDoc,因为注释Ext.data.TreeModel[]与JSDoc兼容,请参阅http://usejsdoc.org/tags-type.html

Closure Compiler从JSDoc语法开始,但在过去5年左右的时间里,两者有所不同。这里描述了闭包编译器注释:https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler(滚动到底部的Type Expressions)。

可能可以更改一些注释以使其与闭包编译器兼容。但是有一些关于代码如何工作的假设,这些假设与编译器的ADVANCED模式一起使用,这个代码可能不会遵循。请参阅a recent thread about a similar question

相关问题