While working on a project where I have a class that extends HTMLElement
, I came across some interesting information in this discussion:
https://github.com/Microsoft/TypeScript/issues/574#issuecomment-231683089
I discovered that I was unable to create an instance of a custom element without encountering an "Illegal constructor" error. Furthermore, the registerElement
method seemed like a solution as it provided the constructor for the custom element, but it has been deprecated in favor of using CustomElementRegistry.define()
. This new method exists on the window object and returns void. Any help or suggestions would be greatly appreciated.
In my specific case, I am choosing to utilize native custom elements instead of a web component framework since I only require custom elements. Additionally, I am working with TypeScript and attempting to incorporate Jest for testing purposes.