我正在尝试使用 Google 的 Closure 编译器编译 ExtJS 6.2.0。 extjs源码中有如下注解:
* @param {Ext.data.TreeModel[]} 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
,但我宁愿以正确的方式执行此操作。
最佳答案
您显示的注释与谷歌闭包编译器不兼容。相反,它会写成
* @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 (滚动到底部的类型表达式)。
可能会更改一些注释以使其与闭包编译器兼容。但是有一些关于代码如何与编译器的 ADVANCED 模式一起使用的工作方式的假设,此代码可能不会遵循这些假设。参见 a recent thread about a similar question .
关于javascript - Google Closure 编译器无法识别类型注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39759819/