使用Google Closure的@typedef标签 [英] Using Google Closure's @typedef tag
问题描述
Google的Closure编译器有一个@typedef标记,但在代码中使用它们是否可以? (我知道它会起作用,但是它不受欢迎吗?)
Google's Closure compiler has an "@typedef" tag, but is it OK to use them in your code? (I know it'll work, but is it frowned upon?)
所以这是我的类型
/**
* The plan object's typedef
* @typedef {Object}
*/
Types.Plan = {
"style": "bordersmall",
"width": "50%",
"height": "40%",
"x": "20%",
"y": "10%",
"clickable": true,
"moveable": true
};
然后我可以在我的JSDoc注释中使用该类型。
And then I can use that type in my JSDoc annotations.
这允许我的IDE在传递的参数上给我自动完成
This allows my IDE to give me autocomplete on the passed parameter
因此声明的对象不会在代码中的任何地方使用。
So the declared object isn't used anywhere in the code.
/**
* 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.
}
这样可以吗?或者有更好的解决方案吗?
So is this ok? Or is there a better solution?
推荐答案
这很好。您还可以使用记录类型来启用编译器的其他类型检查:
This is fine. You can also use a record-type to enable additional type checking with the compiler:
/**
* @typedef {{
* style: string,
* width: string,
* height: string,
* x: string,
* y: string,
* clickable: boolean,
* moveable: boolean
* }}
*/
var myType = ...
http://code.google.com/closure/compiler/docs/js-for-compiler.html#types
这篇关于使用Google Closure的@typedef标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!