runem / web-component-analyzer

CLI that analyzes web components and emits documentation
https://runem.github.io/web-component-analyzer
MIT License
501 stars 61 forks source link

Wrong method type #203

Open pabloalmunia opened 3 years ago

pabloalmunia commented 3 years ago

First of all, I would like to thank the extensive and excellent work is done with this tool. The generation of custom-elements.json from JSDoc comments is helpful in a wide range of situations.

We have a minor error with a class method with two parameters:

The code is:

/**
 * Simple class
 */
class Simple extends HTMLElement {

  /**
   * Fire an event
   * @param {string} event        - event name
   * @param {Object} [detail={}]  - optional event detail object
   * @returns {boolean}           - return true
   */
  fireEvent (event, detail = {}) {
    return this.dispatchEvent (new CustomEvent (
      event,
      {bubbles : true, cancelable : true, detail}
    ));
  }

}

The method type is generated as "type": "(event: string, detail?: string): boolean", but the parameters object defines detail as Object:

{
  "kind": "method",
  "name": "fireEvent",
  "type": "(event: string, detail?: string): boolean",
  "description": "Fire an event",
  "parameters": [
    {
      "name": "event",
      "type": "string",
      "description": "event name"
    },
    {
      "name": "detail",
      "type": "Object",
      "description": "optional event detail object"
    }
  ],
  "return": {
    "description": "return true",
    "type": "boolean"
  }
}

As a result, the method type parameter detail?: string is wrong.