Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM elements are not recognized in custom elements #213

Open
morsh opened this issue Dec 31, 2020 · 0 comments
Open

DOM elements are not recognized in custom elements #213

morsh opened this issue Dec 31, 2020 · 0 comments

Comments

@morsh
Copy link

morsh commented Dec 31, 2020

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/*": [
        "./*"
      ]
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant