【问题标题】:Google Closure Compiler not recognizing type annotationGoogle Closure Compiler 无法识别类型注释
【发布时间】:2016-09-29 01:08:16
【问题描述】:

我正在尝试使用 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,但我宁愿以正确的方式这样做。

【问题讨论】:

    标签: javascript extjs google-closure-compiler


    【解决方案1】:

    您显示的注释与谷歌闭包编译器不兼容。而是写成

    * @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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-15
      • 2013-08-13
      • 2021-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 1970-01-01
      相关资源
      最近更新 更多