谷歌的Closure编译器有一个“@typedef”标签,但你可以在你的代码中使用它们吗? (我知道它会起作用,但它不受欢迎吗?)
所以这是我的类型
/** * The plan object's typedef * @typedef {Object} */ Types.Plan = { "style": "bordersmall","width": "50%","height": "40%","x": "20%","y": "10%","clickable": true,"moveable": true };
然后我可以在我的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. }
这样可以吗?或者有更好的解决方案吗?
解决方法
@typedef用于定义类型,而不是将对象标记为特定类型.如果要将某个变量标记为特定类型,请使用@type {< type>}注释.
@typedef用于定义与@type {…}构造一起使用的“short-hand”类型.
请注意,对象的属性当前未在Closure Compiler中输入,即使已标记,但可能在将来.