简体   繁体   中英

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似乎不喜欢这样

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

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 backquotes

有背引号

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM