代码之家  ›  专栏  ›  技术社区  ›  TylerY86

如何在webtorm中对名称中有点的模块使用JSDoc类型推断?(Discord.js)

  •  0
  • TylerY86  · 技术社区  · 6 年前

    我正试图找到一种方法来处理Discord.js类型脚本注释,该注释使用webtorm的JSDoc类型推断,并且没有冲突。

    import Discord from 'discord.js';
    
    /**
     * @param {Client} client
     * @param {Collection.<Snowflake, Message>} msgs
     */
    function handleRemoveMessages(client, msgs) {}
    

    Message and Snowflake are resolved just fine.

    问题在于客户端,存在多个定义。 The problem is with Client, multiple definitions exist. 在这个过程中,我希望能够从 discord.js 模块化为 Discord.Client 而不是 Client ,因为我想用其他符号命名。

    例如。。。 Message 正在引用正确的类型; Message is referencing the correct type Discord.Message 出现 引用正确的类型(但我不相信它是正确的); Discord.Message appears to be referencing the correct type 两个 类型引用不兼容,并在提供一个引用来表示另一个引用时引发警告。 The two Message type references are not compatible 也不可能通过JSDoc模块路径引用类型。。。 The module path can not be resolved Variation on the module path can not be resolved 我也试过了 module:discord\.js , module:'discord\.js'

    我知道在JSDoc路径名中使用一个点有点麻烦,JetBrains使用的闭包编译器可能没有100%符合JSDoc。

    这只是webtorm或Closure中的一个bug,还是有办法正确地引用这个模块类型?

    1 回复  |  直到 6 年前
        1
  •  2
  •   lena    6 年前

    根据 JSDoc 3 spec ,你需要用“不寻常的”chanracters来引用这些名字,比如 module:"discord.js" . 但目前并没有达到预期的效果,请关注 WEB-34348 用于更新