首页 > 解决方案 > 如何使用@implements

问题描述

我有一个Model类(在 nodejs 中),我想从AuthorizationCodeModel.

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

接口

模型:

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

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

标签: node.jsjsdoc

解决方案


打字稿中的示例界面

interface ClockInterface {
    currentTime: Date;
}

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

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

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

在 WebStorm IDE 上为 distinctlyTyped(TypeScript 类型定义)完成智能感知和代码


推荐阅读