I want to document a type that is defined in a node module (discord.js in my case) so that VS Code can help me with autocompletion.
VS Code supports type hints with JSDoc and this should be the correct way to document the type of the parameter client. Yet VS Code, when I hover over the parameter, says that it is of type any.
(parameter) client: any
This is my code so far
module.exports = class Receiver {
/**
* @param {module:"discord.js".Client} client
*/
constructor(client) {
this.client = client
}
}
How can I make VS Code understand the correct type of the parameter? It should not be any but Client instead.
PS: I have installed the discord.js module and can successfully use it.
require('discord.js')and assign that to a variable, saydiscord, then you should be able to use@param {discord.Client} clientto get your type hinting.require('discord.js')because of the overhead and I would not use the variablediscordanywhere in my code. (discordwould be an unused variable)externfor discord.js. With regard to defining but not usingrequire('discord.js); I agree this is the right solution, and that you should use some sort of tree shaking, whether it be Closure Compiler's "Advanced Optimizations" or Rollup, or a WebPack config, to avoid the file being bundled.require('discord.js')