Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  109] [ 5]  / answers: 1 / hits: 43190  / 11 Years ago, tue, october 22, 2013, 12:00:00

Having next example:



var CONF = {
locale: {
en: {
name: English,
lang: en-US
},
es: {
name: Spanish,
lang: es-ES
}
}
};


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?



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?


More From » dictionary

 Answers
5

According to the JSDoc 3 docs:




Arrays and objects (type applications and record types)



An object with string keys and number values:




{Object.<string, number>}





So it would be:



/** @type {{locales: Object.<string, {name: string, lang: string}>}} */
var CONF = {
locales: {
en: {
name: English,
lang: en-US
},
es: {
name: Spanish,
lang: es-ES
}
}
};


Cleaner, using @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
}
}
};

[#74813] Monday, October 21, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jacquezf

Total Points: 27
Total Questions: 109
Total Answers: 98

Location: Lesotho
Member since Wed, Jun 2, 2021
3 Years ago
;