7

I am very new in JSDoc, and I am trying out Webstorm, so I am also very new on webstorm.

I have on one hand an interface declared this way:

/**  @interface */
function IInterface(){}
IInterface.prototype.myMethod = function(){};

On another hand, I am developing a module in which I am implementing this interface:

window.exports.MyImplementation =  (function(){
    "use strict";

    /**
     *
     * @constructor
     * @implements {IInterface}
     */
    function MyImplementation(){}
    MyImplementation.prototype.myMethod = function(){
        // my implementation here
    };

    return MyImplementation;
})();

The problem I have is that the implementation is apparently not recognized: Not implemented warning screen shot

But if I remove the window.exports.MyImplementation assignation or the return statment, there is no more warning...

enter image description here

.. but I do want to return and store my type from my module!

Is there something I am missing or doing wrong?...

Edit:

Just to bring a bit more confusion to my issue, I was considering using a "full annotation" interface declaration (If it is possible, I am experimenting here...):

enter image description here

... but in this case, you can notice that the "I" symbol has disappeared from the left side and if the method is not implemented, I don't have any warning. BUT the type IInterface is recognized.

Edit: I think I just understood something while experimenting other stuffs of jsDoc. The warning is thrown because the check on the implementation is made on the window.exports.MyImplementation. But there is no direct assignation implementing this object in the code. And this is why the warning is disabled when I remove the return statement or the "exports.MyImplementation" assignation.

.. thus, not sure this could be considered as a bug, this may be the pattern I used for my module that doesn't match to the pattern expected by WebStorm and maybe also by the JSdoc itself...... If someone who has experience in JSDoc and Webstorm could confirm.....

Another edit: (significant step here in understanding JSDoc I think)

The annotations have been moved on the targeted field and... tadaaa (notice the "I" which is still here indicating the interface is indeed implementing).

enter image description here

My explanation: There could be a logic behind that.... but honestly I really don't know if it is relevant: as the documented field will be exported in "exports.MyImplementation" at the very end, and this is evident the annotation is more useful here than in the private enclosure. WebStorm has detected the exportation to "exports.MyImplementation", thus is waiting for the documentation on it...

Does it make sense?...

And another edit (again) Investigation, investigation.

I have found a quite different solution that allows documentation, completion, validation and no warning, which seems to me a better solution for module exportation: enter image description here

7
  • I guess because your declaration of MyImplementation is technically "finished" in line 66 without implementing all necessary functions of the interface. I suppose you have to integrate the method implementation into the declaration of MyImplementation, not add it to the prototype later on.
    – kasoban
    Nov 13, 2014 at 14:15
  • Thanks for your suggestion kasoban, but implementation in the body doesn't change anything. Moreover, I really want to implement it using prototyping. Ideally, if there was a solution changing annotations, it would perfectly fit what need :-) Nov 13, 2014 at 14:19
  • Hmm, as far as I understand the documentation your code should be fine, aside from the missing semicolons at the end of line 66 and line 55. Maybe that confuses the inspector somehow?
    – kasoban
    Nov 13, 2014 at 14:24
  • Thanks again kasoban... however, as far as I understand "hoisting" in javascript, is seems to me that there shouldn't have semicolons in these cases :-). Anyway, adding semicolons still doesn't change anything :-( Nov 13, 2014 at 14:28
  • Yeah, you don't necessarily need semicolons there, but they don't hurt either. Was just a wild guess :)
    – kasoban
    Nov 13, 2014 at 14:30

1 Answer 1

2

it's a bug in WebStorm JSDoc support, please vote for WEB-14202

2
  • Ok, this seems to be the good answer indeed: when you try to do implementation out of the module, but without the namespace prefix, this works even if the targeted object is wrong....... Thanks for the bugtracker update Nov 13, 2014 at 16:49
  • According to my further investigations, I am less and less convinced this could be a bug Nov 13, 2014 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.