Include type hints in JSDocs for Lightning

Issue #1041 resolved
Andrew Visser created an issue

Steps:

  • Create a Lightning component & controller
  • create a method doInit
  • annotate the method with the following
    /**
     *
     * @param cmp {Component}
     * @param event
     * @param helper
     */
     doInit: function(cmp, event, helper)
  • Start typing in the method body cmp.find('foo').

Expected behavior: I get an autocomplete pop-up with all of the methods that you've documented in Component.js

Actual Behavior: no pop-up

This can be fixed by adding * @return {Component} to the jsDoc for the find method

Comments (5)

  1. Scott Wells repo owner

    Andy, I apologize but I'm not sure I understand the issue. Here's what I see when I type component.f in IntelliJ IDEA Ultimate Edition or WebStorm's JavaScript editor (note that none of this will work in Community Edition):

    Issue1041.png

    I've also verified that if you rename component to cmp, it yields the same results. Note, though, that our JSDoc is slightly different with mine having @param {Type} name and yours having @param name {Type} as documented here:

    http://usejsdoc.org/tags-param.html#names-types-and-descriptions

    However, just for completeness' sake, I did swap the order and saw the same correct results in the IDE.

    As for changing the JSDoc, if you do find errors, you'll need to log them against the official Aura project as the JavaScript API interfaces for Lightning/Aura are pulled directly from that project and only modified to extract the accessible interfaces (i.e., function bodies are stripped for efficiency).

    Please let me know if I'm misunderstanding the nature of this reported issue or if you're not seeing the same behavior.

  2. Scott Wells repo owner

    I'm going to resolve this as unable to reproduce based on the comment I just added, but if I've misunderstood the issue or if you're doing exactly what I describe and are seeing different behavior, please open with appropriate details.

  3. Andrew Visser Account Deactivated reporter

    You've provided a good answer: fixing the docs in the Aura codebase.

    The issue was on the result of cmp.find()., not cmp. I'd love both to produce the same results, as they are both components.

  4. Scott Wells repo owner

    Ah, I see now. You're wanting to get completions off of cmp.find() which should evaluate to Component. Sorry, not sure how I missed that as you described it perfectly. Yeah, I've sent some other feedback to the Aura team about their JSDoc. I'd definitely recommend that you do the same, or perhaps even provide a pull request to them if they'll accept it. Thanks for clarifying!

  5. Log in to comment