我有一个
Model
类(在nodejs中),我想从AuthorizationCodeModel
实现它。
我希望 WebStorm 检测到我的模型实现了该接口并建议我自动完成
界面.
型号:
/**
* @implements AuthorizationCodeModel
*/
class Model {
}
@implements AuthorizationCodeModel
不起作用。如何使用 JSDoc?
打字稿中的示例界面
interface ClockInterface {
currentTime: Date;
}
class Clock implements ClockInterface {
currentTime: Date;
constructor(h: number, m: number) { }
}
https://www.typescriptlang.org/docs/handbook/interfaces.html
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
以防万一有人最终在这里寻求他们想要导入的“
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% 原始问题,但我可以看到遇到我的问题的人也在这里结束。