javascript - JSDoc 一个对象,无论名称如何,所有属性都获得相同的类型
问题描述
我想将 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: {
...
},
});
解决方案
看起来你想要
/**
* @param {Object.<string, EmojiGroupContent>} groups
*/
推荐阅读
- javascript - 如何在使用另一个状态而不导致无限更新的情况下更新父级的状态?
- php - 根据搜索到的用户 ID 显示具有最新日期的结果
- python-3.x - 无法导入 colorama 模块
- android - 在firebase中保存svg的最佳方法是什么?
- algorithm - 解决旅行商问题以在最短的时间内最大化收益
- google-chrome-os - 在戴尔 XPS 13 上安装 chromeOS 时卡在引导循环中
- html - 什么是网格模板列中的自动调整?
- java - 在 Spring Security dofilter 身份验证方法中使用 @Autowired 注释时出现 Nullpointer 异常
- rust - 切片是否有额外的动态数据?
- c++ - 比较运算符可以在 C++20 中的类定义之外默认吗?