如何在名称中带有点的模块上的WebStorm中使用JSDoc类型推断? (Discord.js) [英] How do I use JSDoc type inference in WebStorm on a module with a dot in it's name? (Discord.js)

查看:200
本文介绍了如何在名称中带有点的模块上的WebStorm中使用JSDoc类型推断? (Discord.js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种以非冲突模式使用WebStorm的JSDoc类型推断来使用Discord.js TypeScript注释的方法.

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.

这是作品" ...

import Discord from 'discord.js';

/**
 * @param {Client} client
 * @param {Collection.<Snowflake, Message>} msgs
 */
function handleRemoveMessages(client, msgs) {}

问题出在客户端上,存在多个定义. 在执行此操作的同时,我希望能够将discord.js模块中导入的类型的名称空间命名为Discord.Client而不是Client之类的名称空间,因为我想使用其他命名为此类的符号.

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.

因此,例如... Message引用了正确的类型; 并且Discord.Message 出现指向正确的类型(但我不相信这是正确的); 两个Message类型引用不兼容,并且在提供一个表示另一个时会引发警告. 也不可能通过JSDoc模块路径来引用类型... 我还尝试了module:discord\.jsmodule:'discord\.js'以及双引号,所有结果都相同.

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.

我知道在JSDoc路径名中使用点有点麻烦,而且JetBrains使用的Closure编译器可能无法达到JSDoc要求的100%.

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.

这仅仅是WebStorm或Closure中的错误,还是有一种方法可以正确地引用此模块类型?

Is this just a bug in WebStorm or Closure or is there a way to correctly make this module type reference?

推荐答案

根据 JSDoc 3规范,您需要用不寻常的"字符引用名称,例如module:"discord.js".但目前无法正常运行,请按照 WEB-34348 进行更新

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

这篇关于如何在名称中带有点的模块上的WebStorm中使用JSDoc类型推断? (Discord.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆