Jam*_*May 6 javascript google-closure-compiler jsdoc pixi.js
我正在为pixijs库准备externs文件以使用闭包编译器.到目前为止我唯一的问题是使用自定义对象参数.这是一个简短的例子:
pixi.js来源:
/**
* Set the style of the text
*
* @param [style] {object} The style parameters
* @param [style.font='bold 20pt Arial'] {string} The style and size of the font
* @param [style.fill='black'] {string|number} A canvas fillstyle that will be used on the text eg 'red', '#00FF00'
* @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text
Run Code Online (Sandbox Code Playgroud)
闭包编译输出:
lib/pixi-externs.js:3266: WARNING - Parse error. invalid param name "style.font"
* @param [style.font='bold 20pt Arial'] {string} The style and size of the font
^
lib/pixi-externs.js:3266: WARNING - Bad type annotation. missing closing ]
* @param [style.font='bold 20pt Arial'] {string} The style and size of the font
^
lib/pixi-externs.js:3267: WARNING - Parse error. invalid param name "style.fill"
* @param [style.fill='black'] {string|number} A canvas fillstyle that will be used on the text eg 'red', '#00FF00'
^
lib/pixi-externs.js:3268: WARNING - Parse error. invalid param name "style.align"
* @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text
^
Run Code Online (Sandbox Code Playgroud)
这些pixijs注释如何适应闭包编译器注释?
如果没有办法通过注释实现这一点,我可以通过定义一个新对象来克服这个问题吗?
* @param {PIXI.TextStyleObject} style The style parameters
Run Code Online (Sandbox Code Playgroud)
并创建一个单独的TextStyleObject对象定义?
PIXI.TextStyleObject = {};
PIXI.TextStyleObject.font;
PIXI.TextStyleObject.fill;
PIXI.TextStyleObject.align;
Run Code Online (Sandbox Code Playgroud)
解决这个问题的正确方法是什么?
您将需要使用记录对象来执行此操作:
/** @param {{
* font: string,
* fill: string,
* align: string
* }} object
*/
Run Code Online (Sandbox Code Playgroud)
如果您发现自己多次重复使用同一个记录对象,则可以使用 typedef 为其指定别名:
/** @typedef {{
* font: string,
* fill: string,
* align: string
* }}
*/
var PixiStyleOptions;
/** @param {PixiStyleOptions} object */
Run Code Online (Sandbox Code Playgroud)