Search code examples
javascriptnode.jswebstormjsdocdiscord.js

How to use a type from another module as a JSDoc return/param type


I'm trying to use JSDoc to document some functions of a bot I'm making:

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;
};

As you can see, this function returns a RichEmbed object from the discord.js module, but WebStorm doesn't seem to like that.

WebStorm doesn't seem to like that

So, how do I use a type from another module in JSDoc?


Solution

  • Because of WebstormProblem any modules with a . dot/period in it's module name can cause problems.

    A workaround that seems to work on my end is, Use ESMA6 and use backquotes to require the module.

    With regular quotes

    With regular quotes

    With backquotes

    With back quotes