wix-incubator / corvid

Download your Wix site, code in a local IDE, collaborate, use git, and more!
MIT License
38 stars 10 forks source link

DOM elements are not recognized in custom elements #213

Open morsh opened 3 years ago

morsh commented 3 years ago

When writing web components (aka custom elements), I need to write something like:

export const createImage = (src) => {
    const imageElement = document.createElement('img');
    imageElement.src = '...';
    imageElement.id = 'some-image';
    return imageElement;
};

class MyCustomElement extends HTMLElement {
  connectedCallback() {
    this.appendChild(createImage());
  }
}

customElements.define('my-custom-element',  MyCustomElement);

In the above code, HTMLElement; document; this.appendChild; customElements.define are all not defined. A simple solution would be to add "lib": ["es2016", "dom"] to the tsconfig file generated in public/ folder, like so:

{
  "extends": "corvid-types/configs/tsconfig.public.json",
  "compilerOptions": {
    "baseUrl": ".",
    "lib": [ "es2016", "dom" ],
    "paths": {
      "public/*": [
        "./*"
      ]
    }
  }
}