【问题标题】:How can I define the type of a class param in JSDoc?如何在 JSDoc 中定义类参数的类型?
【发布时间】:2023-03-15 04:05:02
【问题描述】:

我有一个项目,其中包含一些 Web 组件类,并且我还有一个接收这些组件并将它们注册到窗口中的函数。 例如:

/**
* @param {} ComponentClass - class that extends HTMLElement
* @param {string} displayName - tag name to be used in html
*/
function registerComponent(ComponentClass, displayName){
  window.customElements.define(displayName, ComponentClass);
}

我的问题是:如何正确输入 ComponentClass?有没有办法描述它是一个扩展 HTMLElement 的类?

【问题讨论】:

    标签: javascript html documentation web-component jsdoc


    【解决方案1】:

    CustomElementConstructor 是你所追求的,例如

    /**
     * @param {CustomElementConstructor} ComponentClass - class that extends HTMLElement
     * @param {string} displayName - tag name to be used in html
     */
    function registerComponent(ComponentClass, displayName) {
      window.customElements.define(displayName, ComponentClass);
    }
    
    class WCTest extends HTMLElement {}
    
    registerComponent(WCTest, 'wc-test');
    

    【讨论】:

      猜你喜欢
      • 2018-03-12
      • 2020-11-18
      • 2017-11-21
      • 1970-01-01
      • 2013-04-07
      • 2012-12-17
      • 1970-01-01
      • 2016-04-24
      • 1970-01-01
      相关资源
      最近更新 更多