javascriptnode.jsjsdoccode-documentation

JSDoc object with value props as key


I have an items object with Items like this:

class Item {
    /**
     *@type {number}
     */
    id;
}

let items = {};

I want to document the fact that keys of items is value.id is there a way ot do so?

Currently I'm using this syntax.

/**
 * @type {{[item_id:number]:Item}}
 */
let items = {};

Solution

  • You can use Record

    /**
     * @type {Record<Item['id'], Item>}
     */
    let items = {};