PhpStorm finds the TypeScript header file for declaration but doesn't use it

Here's a function with a docblock:

/**
* @param {Discord.Message} message
* @return {Promise}
*/
let messageHandler = message => {
if (message.content === 'Ping') return message.channel.send('Pong');
};

PhpStorm correctly discovers the declaration file:

Clearly, property `content` is defined on `Message`:

But PhpStorm doesn't offer any autocompletion or use the header file correctly:

I searched around for a solution, tried adding the library which the header file belongs to (discord.js) to JavaScript libraries manually, but PhpStorm refuses to use the header file correctly.

 

This issue has actually been plaguing me for a while with numerous other JavaScript projects, including the cases when I define a `*.d.ts` file by hand to make use of interfaces and other perks of TypeScript in my ES6 (with JSDoc comments).

 

Could you please advise?

0
4 comments
Avatar
Permanently deleted user

The issue disappears when I use just `Message` as the type, but I'd still like to reference the module. In this case, the module name contains a period:

So I can't reference the name of the module directly in my JS doc.

0

please can you provide your discord.js d.ts file?

0
Avatar
Permanently deleted user

Hello, apologies for the late reply.

The file I used is identical to this one:

 

https://github.com/zajrik/discord.js-typings/blob/0b5b13f4a521cba0fc42aa0f9b2c4a1abca2de3d/index.d.ts

 

I'm not quite sure what exactly is causing the issue, but as you know PhpStorm tries to autocomplete JSDoc doc blocks, and when you try to use `@type` autocompletion on `const Discord = require('discord.js');` PhpStorm guesses `@type {"discord.js".Message}`, which isn't a valid JSDoc type as far as I'm aware.

0

Well... Why do you expect {Discord.Message} to work? the d.ts file doesn't have Discord namespace declared anywhere... The only available namespace is discord.js, so PhpStorm works as expected... And "discord.js".Message is a valid JSDoc namepath - names with special characters are surrounded with quotes, see http://usejsdoc.org/about-namepaths.html#namepaths-in-jsdoc-3, Namepaths of objects with special characters in the name. The only problem is that PhpStorm doesn't always work with such namepaths - https://youtrack.jetbrains.com/issue/WEB-18032

0

Please sign in to leave a comment.