【问题标题】:JSDoc an Object, all properties regardless of name get same typeJSDoc 一个对象,无论名称如何,所有属性都获得相同的类型
【发布时间】:2020-08-19 02:03:43
【问题描述】:

我想将 JSDocs 添加到我的函数中。我不知道如何定义一个键不重要的对象(每个键都指向相同类型的对象)。有什么方法可以实现吗?

/**
 * @typedef EmojiGroupContent
 * @type {Object}
 * @prop {string[]} emojis All Emojis belonging to the group
 * @prop {function} onAdd Runs when the group is unlocked
 *                        (no other emoji in the group is active),
 *                        and the user reacts with an emoji from this group.
 * @prop {function} onDel Runs when the user removes a reaction belonging to this group.
 */
/**
 * @param {object} pool INSTANCE OF POOL
 * @param {Object} groups
 * @param {EmojiGroupContent} groups.anyNameHere <= Can I force all the properties to be of
 *                                               the type EmojiGroupContent, would it also
 *                                               be possible to have the keys to have a JsDoc
 *                                               comment.
 */
const registerEmojiInteraction = (pool, groups) => {
  ...
};

registerEmojiInteraction(POOL, {
  race: {
    emojies : ["", ...],
    onAdd : ()=>{},
    onDel : ()=>{},
  },
  vsrace: {
    ...
  },
});

【问题讨论】:

    标签: javascript jsdoc


    【解决方案1】:

    看起来像你想要的

    /**
     * @param {Object.<string, EmojiGroupContent>} groups
     */
    

    【讨论】:

    • i.imgur.com/ecRmlrQ.png 它不显示EmojiGroupContent 的内容,只是它是类型,但自动完成工作。这正常吗?
    • 我想没关系。这就是我希望看到的这种情况
    猜你喜欢
    • 2022-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    • 1970-01-01
    • 2016-01-04
    • 2017-08-05
    • 1970-01-01
    相关资源
    最近更新 更多