问题
I'm trying to find a way to work with Discord.js TypeScript annotations using WebStorm's JSDoc type inference in a non-conflicting pattern.
Here's what "works"...
import Discord from 'discord.js';
/**
* @param {Client} client
* @param {Collection.<Snowflake, Message>} msgs
*/
function handleRemoveMessages(client, msgs) {}
The problem is with Client, multiple definitions exist.
While this works, I'd like to be able to namespace the imported types from the discord.js
module into something like Discord.Client
instead of Client
, as I'd like to use other symbols named such.
So, for example... Message
is referencing the correct type;
And Discord.Message
appears to be referencing the correct type (but I don't believe it is);
The two Message
type references are not compatible, and throw a warning when one is supplied to represent the other.
It's also not possible to reference the type via a JSDoc module path...
I also tried module:discord\.js
, module:'discord\.js'
and also with double quotes, all with the same results.
I know that using a dot in a JSDoc path name is a bit of a hack, and that the Closure compiler used by JetBrains may not be 100% up on JSDoc compliance.
Is this just a bug in WebStorm or Closure or is there a way to correctly make this module type reference?
回答1:
according to JSDoc 3 spec, you need to quote the names with 'unusual' chanracters, like module:"discord.js"
. But it doesn't currently work as expected, please follow WEB-34348 for updates
来源:https://stackoverflow.com/questions/51793858/how-do-i-use-jsdoc-type-inference-in-webstorm-on-a-module-with-a-dot-in-its-nam