Javascript 使用谷歌闭包';s@typedef标签
谷歌的闭包编译器有一个“@typedef”标记,但在代码中使用它们可以吗?(我知道它会起作用,但它会被反对吗?) 这是我的类型 /** * The plan object's typedef * @typedef {Object} */ Types.Plan = { "style": "bordersmall", "width": "50%", "height": "40%", "x": "20%", "y": "10%", "clickable": true, "moveable": true }; /** *计划对象的typedef *@typedef{Object} */ 类型。计划={ “风格”:“边缘小”, “宽度”:“50%”, “高度”:“40%”, “x”:“20%”, “y”:“10%”, “可点击”:正确, “可移动”:真 }; 然后我可以在我的JSDoc注释中使用这种类型 这允许IDE对传递的参数进行自动完成 因此声明的对象在代码中的任何地方都没有使用 /** * The Instructions class * @param {Types.Plan} plan Plan for position and dimension * @param {Manager} manager The manager * @param {Instructions} parent This widget's parent's instructions * @return {Instructions} Returns the new instructions object */ Instructions = function(plan, manager, parent){ plan. } /** *指导课 *@param{Types.Plan}位置和维度的平面图 *@param{Manager}Manager经理 *@param{Instructions}parent此小部件的父指令 *@return{Instructions}返回新的指令对象 */ 说明=职能(计划、经理、上级){ 计划。 }Javascript 使用谷歌闭包';s@typedef标签,javascript,google-closure-compiler,google-closure,jsdoc,Javascript,Google Closure Compiler,Google Closure,Jsdoc,谷歌的闭包编译器有一个“@typedef”标记,但在代码中使用它们可以吗?(我知道它会起作用,但它会被反对吗?) 这是我的类型 /** * The plan object's typedef * @typedef {Object} */ Types.Plan = { "style": "bordersmall", "width": "50%", "height": "40%", "x": "20%", "y": "10%", "clickab
这样行吗?还是有更好的解决方案?这很好。还可以使用记录类型启用编译器的其他类型检查:
/**
* @typedef {{
* style: string,
* width: string,
* height: string,
* x: string,
* y: string,
* clickable: boolean,
* moveable: boolean
* }}
*/
var myType = ...
@typedef
用于定义类型,而不是将对象标记为特定类型。如果要将某个变量标记为某个类型,请使用@type{}
注释
@typedef
用于定义与@type{…}
构造一起使用的“速记”类型
请注意,对象的属性当前未在闭包编译器中键入(即使已标记),但将来可能会键入。typedef用于创建类型,因此不建议将其用作名称空间(为其指定对象文字)。不久前,我写了一篇关于各种typedef陷阱的文章。它对联合也很有用:
/**@typedef{string | number | boolean}*/var myTypePer,JSDoc@property,因此这种记录类型语法是唯一的选择。