【问题标题】:How to use @implements如何使用@implements
【发布时间】:2019-02-03 23:36:28
【问题描述】:

我有一个 Model 类(在 nodejs 中),我想从 AuthorizationCodeModel 实现它。

我希望 WebStorm 检测到我的模型实现了接口并建议我自动完成

Interface.

型号:

  /**
   * @implements AuthorizationCodeModel
   */
  class Model {
  }

@implements AuthorizationCodeModel 不工作。如何使用 JSDoc?

【问题讨论】:

    标签: node.js jsdoc


    【解决方案1】:

    打字稿中的示例界面

    interface ClockInterface {
        currentTime: Date;
    }
    
    class Clock implements ClockInterface {
        currentTime: Date;
        constructor(h: number, m: number) { }
    }
    

    https://www.typescriptlang.org/docs/handbook/interfaces.html

    What's the difference between 'extends' and 'implements' in TypeScript

    JSDOC 示例:http://usejsdoc.org/tags-implements.html


    如果 Webstorm 中的自动完成功能不起作用,请尝试设置 reference path in js file

    /// <reference path="components/someClass.js"/>
    /// <reference path="components/someInterface.js"/>
    /// <reference path="components/AuthorizationCodeModel.js"/>
    
    /**
    * @implements AuthorizationCodeModel
    */
    class Model { }
    

    Reference paths 在一些流行的 IDE 中也用于自动完成

    https://madskristensen.net/blog/the-story-behind-_referencesjs

    https://www.jetbrains.com/help/webstorm/configuring-javascript-libraries.html

    https://intellij-support.jetbrains.com/hc/en-us/community/posts/206352279-How-to-not-reference-other-js-files

    intellisense and code complete for DefinitelyTyped (TypeScript type definitions) on WebStorm IDE

    【讨论】:

    • 我不使用 typescript ,我的代码是 nodejs 代码,而 type 脚本代码是由 distinctlyTyped 创建的存根
    • 正如我提到的@implements AuthorizationCodeModel 不起作用,WebStorm 不建议我自动完成
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 2020-05-11
    相关资源
    最近更新 更多