Consider the following:
class MyCustomElement extends HTMLElement {}
customElements.define('my-custom-element', MyCustomElement);
/** @type {MyCustomElement} */
const myCustomElement = document.createElement('my-custom-element');
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The myCustomElement would be an instance of MyCustomElement at runtime (a derivation of HTMLElement); but, type-hinting the myCustomElement makes the JetBrains IDE of PhpStorm to complain:
Initializer type
HTMLElementis not assignable to variable typeMyCustomElement
Surprisingly, the IDE is totally fine on the built-in types:
/** @type {HTMLDivElement} */
const myDiv = document.createElement('div');
So, what should I do to have the very appropriate "typing hints" to the IDE (not using *) while having the warning resolved?!
I could've instantiate the
myCustomElement using the new operator; and it seems to work, but there is no reference on the differences between the approaches (on whether to use new or to use document.createElement(), and why or why-not to choose one over the other?!)