【问题标题】:How to use a type from another module as a JSDoc return/param type如何使用来自另一个模块的类型作为 JSDoc 返回/参数类型
【发布时间】:2018-10-17 18:33:03
【问题描述】:

我正在尝试使用 JSDoc 来记录我正在制作的机器人的一些功能:

const Discord = require("discord.js");

/**
 * Returns and empty embed with the bot's default settings
 * @param u - The user that executed the command
 * @returns {Discord.RichEmbed}
 */
exports.getDefaultEmbed = function(u) {
    let embed = new Discord.RichEmbed();
    embed.setColor(0xFA632A);
    if (u) embed.setFooter(u.tag, u.displayAvatarURL);
    return embed;
};

如您所见,此函数从discord.js 模块返回一个 RichEmbed 对象,但 WebStorm 似乎不喜欢这样。

那么,如何在 JSDoc 中使用来自另一个模块的类型?

【问题讨论】:

  • RichEmbed() 声明是什么样的(导出、记录等的方式)?
  • 您使用的是哪个分支?因为在 master 里 RichEmbed 已经不存在了,它只是在 stable 中。在 master 中,它现在是 MessageEmbed,而在 stable 中 MessageEmbed 仅用于接收到的消息。

标签: javascript node.js webstorm jsdoc discord.js


【解决方案1】:

由于WebstormProblem,任何模块名称中带有. 点/句点的模块都可能导致问题。

似乎对我有用的解决方法是,使用 ESMA6 并使用反引号来要求模块。

带常规引号

带反引号

【讨论】:

    猜你喜欢
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    相关资源
    最近更新 更多