如何使用@implements

问题描述 投票:0回答:2

我有一个

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

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

界面.

型号:

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

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

node.js jsdoc
2个回答
0
投票

打字稿中的示例界面

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 上的DefinitelyTyped(TypeScript 类型定义)的智能感知和代码已完成


0
投票

以防万一有人最终在这里寻求他们想要导入的“

interface
”,事实证明,如果您从一个模块导出
interface
,则必须使用
class
语句;不是
class
表达式。

如果您尝试使用这样的导入界面:

const { MyInterface } = require('./interfaceFile');

/**
 * @implements MyInterface
 */
class MyImplementation {

}

不起作用:

/**
 * @interface
 */
module.exports.MyInterface = class MyInterface {
   . . .
}

会起作用:

/**
 * @interface
 */
class MyInterface {
   . . .
}

module.exports.MyInterface = MyInterface;

不是 100% 原始问题,但我可以看到遇到我的问题的人也在这里结束。

© www.soinside.com 2019 - 2024. All rights reserved.