模板化对象的JSDoc对象 [英] JSDoc Object of templated objects
问题描述
有没有办法可以松散地指定您要记录的对象中应该包含哪些类型的对象?
Is there a way to loosely specify what type of objects should be inside the object you're documenting?
我想要记录以下对象:
var obj = {
unknownName1: {
name: "KnownValue"
},
unknownName2: {
name: "KnownValue",
offset: {
x: 0,
y: 0
}
},
unknownName3: {
name: "KnownValue",
offset: {
x: 0,
y: 0
},
visible: true
},
unknownName4: {
name: "KnownValue"
}
};
子对象应具有以下属性:
The sub objects should have the following properties:
/**
* Example Object
* @typedef myObject
* @type {Object}
* @property {String} name - Name of the templated object
* @property {Number} [offset.x] - Offset X
* @property {Number} [offset.y] - Offset Y
* @property {Boolean} [visible] - Is Visible
* @memberof com.namespace.MyClass
*/
如果我想记录这个特定的 obj
我将执行以下操作,但该对象将使用未知数量的未知名称的对象动态生成 com.namespace.MyClass的类型
If I wanted to document this specific obj
I would do the following, but the object will be dynamically generated with an unknown number of objects of unknown name with the type of com.namespace.MyClass
/**
* Object of Special Objects
* @typedef mySpecialObjectOfObjects
* @type {Object}
* @property {com.namespace.MyClass.myObject} unknownName1
* @property {com.namespace.MyClass.myObject} unknownName2
* @property {com.namespace.MyClass.myObject} unknownName3
* @property {com.namespace.MyClass.myObject} unknownName4
* @memberof com.namespace.MyClass
*/
PS我只是在寻找可以使用的通配符 @property
,这样我的编辑器就可以帮助我记住对象中每个子对象的所有可用选项。
P.S. I'm just looking for a wildcard @property
that can be used so my editor can help me remember all the options available for each sub-object inside the object.
推荐答案
按 http ://usejsdoc.org/tags-type.html ,从JSDoc 3.2开始,JSDoc完全支持Google Closure Compiler类型表达式。 http://usejsdoc.org/tags-type.html#中描述了一种此类格式。 jsdoc-types :
Per http://usejsdoc.org/tags-type.html , as of JSDoc 3.2, JSDoc has had full support of Google Closure Compiler type expressions. One such format is described at http://usejsdoc.org/tags-type.html#jsdoc-types :
{Object.<string, number>}
所以在你的情况下,你应该可以这样做:
So in your case, you should be able to do:
/**
* Object of Special Objects
* @typedef mySpecialObjectOfObjects
* @type {Object.<string, com.namespace.MyClass.myObject>}
* @memberof com.namespace.MyClass
*/
你甚至可以如果你想要一个特殊的类型专用于详细说明允许字符串值的名称,那么用它自己的类型替换 string
。
You could even replace string
there with its own type, if you wanted to have a special type dedicate to the name detailing the allowable string values.
这篇关于模板化对象的JSDoc对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!