A.A
A.A

Reputation: 4081

How to use @implements

I have a Model class (in nodejs) and I want to implement it from AuthorizationCodeModel.

I want WebStorm detect that my model implemented the interface and suggest me auto complete

Interface.

Model:

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

the @implements AuthorizationCodeModel is not working. How can I use JSDoc?

Upvotes: 5

Views: 2277

Answers (2)

Carcigenicate
Carcigenicate

Reputation: 45726

Just in case someone ends up here for an "interface" that they implement that they're trying to import, it turns out if you're exporting an interface from one module, you must use a class statement; not a class expression.

If you're trying to use an imported interface like this:

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

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

}

Will not work:

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

Will work:

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

module.exports.MyInterface = MyInterface;

Not 100% the original issue, but I can see people who are having my issue also ending up here.

Upvotes: 1

аlex
аlex

Reputation: 5698

example interface in typescript

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 examples: http://usejsdoc.org/tags-implements.html


If autocomplete in Webstorm not worked, try to set 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 also use for autocomplete in some popular IDEs

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

Upvotes: 0

Related Questions