I have a project that has some web-components classes and I also have a function that receive those components and register them into the window. For example:
/**
* @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);
}
my question is: how can I correctly type ComponentClass? is there a way to describe that it's a class that extends HTMLElement?
CustomElementConstructor
is what you are after, eg
/**
* @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');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.