我的 grunt 任务 jsdoc 遇到了这个 jsdoc,它描述了一个对象文字数组:
/**
* @type {{sku:string,
* stockColor:string,
* validTo:string,
* price:string,
* availableStock:string}[]} data
*
*/
var variations = [];
来自 Grunt 的错误消息如下:
D:\dev\ngs-frontend>grunt jsdoc Running "jsdoc:dist" (jsdoc) task
block 引用> block 引用>ERROR: Unable to parse a tag's type expression for source file D:\dev\ngs-frontend\src\assets\js\modules\content\product-detail\hse-productdetails.js with tag title "type" and text "{{sku:string, stockColor:string,
validTo:string, price:string, availableStock:string}[]}": Invalid type expression "{sku:string, stockColor:string,
validTo:string, price:string, avail ableStock:string}[]": Expected "!", "=", "?", "|" or end of input but "[" found.据我所知,JSDoc 对我来说是正确的。也许 grunt jsdoc 编译器有问题?
我正在定义一个对象文字数组。据我所知:
{{名称:值, name2:值2}[]}
这是描述这一点的正确方式。
最佳答案
这是 jsdoc 本身的一个错误/不支持的语法(用 jsdoc 3.4.0 尝试过),而不是 grunt。您可能应该向他们报告 https://github.com/jsdoc3/jsdoc/issues/ 上的错误
支持语法 @type { {a : String, b : Number} }
,但不支持 @type { {a : String, b : Number}[] }
您可以使用 @typedef
来解决这个问题,例如:
/**
* @typedef { {
* sku:string,
* stockColor:string,
* validTo:string,
* price:string,
* availableStock:string }} variation
*/
/**
* @type {variation[]}
*/
var variations = [];
关于javascript - 根据 Grunt 的说法,JSDoc 不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35551289/