How can I document randomly-assigned properties of a custom type in JSDoc?

334 Views Asked by At
/**
 * @typedef {string} UUID
 * */

/**
 * @typedef {Object} ITEM
 * @property {UUID} id
 * */

/** 
 * @typedef {Object} THINGY
 * @property {??????}
 * */

const oneThingy = {
 asdf: {id: 'asdf', ...},
 sdfg: {id: 'sdfg', ...},
 dfgh: {id: 'dfgh', ...}
}

Assuming that a THINGY can have infinite k:v pairs, and that the keys will be random UUIDs, how would I document and type the @property?

1

There are 1 best solutions below

0
grilchgristle On

Thanks to a kind person named Kyriakos on the JSDoc Slack channel, TIL it's not the @property, I just need the properly-formatted @typedef:

/**
 * @typedef {string} UUID
 * */

/**
 * @typedef {Object} ITEM
 * @property {UUID} id
 * */

/** 
 * @typedef {Object.<UUID, ITEM>} THINGY // <-- this one
 * */

const oneThingy = {
 asdf: {id: 'asdf', ...},
 sdfg: {id: 'sdfg', ...},
 dfgh: {id: 'dfgh', ...}
}