如何在JSDoc中记录字典? [英] How to document a dictionary in JSDoc?
本文介绍了如何在JSDoc中记录字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有下一个例子:
var CONF = {
locale: {
"en": {
name: "English",
lang: "en-US"
},
"es": {
name: "Spanish",
lang: "es-ES"
}
}
};
知道locale属性包含的是一个字典对象,它来自数据库,怎么能我用JSDoc记录它的内部属性?
And knowing that what the locale property contains is a dictionary object, which comes from the database, how can I document its inner properties with JSDoc?
目前我正在考虑 typedef
我的语言环境对象的类型,然后可能我能够将 locale
属性设置为我定义的类型的数组?这是正确的方法吗?
Currently I am thinking to typedef
type for my locale objects, then may I be able to set the locale
property to simply an Array of my defined type? Is this the right way to do it?
推荐答案
根据 JSDoc 3 docs :
数组和对象(类型应用程序和记录类型)
Arrays and objects (type applications and record types)
具有字符串键和数字值的对象:
An object with string keys and number values:
{Object。< string,number>}
所以它会是:
/** @type {{locales: Object.<string, {name: string, lang: string}>}} */
var CONF = {
locales: {
en: {
name: "English",
lang: "en-US"
},
es: {
name: "Spanish",
lang: "es-ES"
}
}
};
清洁,使用 @typedef
/**
* @typedef {{name: string, lang: string}} locale
*/
/**
* @type {{locales: Object.<string, locale>}}
*/
var CONF = {
locales: {
en: {
name: "English",
lang: "en-US"
},
es: {
name: "Spanish",
lang: "es-ES"
}
}
};
这篇关于如何在JSDoc中记录字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文