Skip to content

improve type definition for custom element class/instance #222

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

Merged

Conversation

keithamus
Copy link
Contributor

This PR changes the typedef for CustomElement to be CustomElementClass which changes from:

interface new CustomElement {
  new(): HTMLElement
}

to

interface new CustomElementClass {
  new(): CustomElement
//...
}

The CustomElement type then extends HTMLElement but adds all the optional callbacks that make up a Custom Element, e.g. ConnectedCallback.

This isn't necessary for the existing code, but it will enable us to have more safe guards in future as we work with these methods, because TS will now check that we're interacting with them correctly.

@keithamus keithamus requested a review from a team as a code owner May 5, 2022 13:42
@keithamus keithamus requested review from srt32 and koddsson May 5, 2022 13:42
@keithamus keithamus merged commit 44f8a23 into main May 5, 2022
@keithamus keithamus deleted the improve-type-definition-for-custom-element-class-instance branch May 5, 2022 13:59
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

Successfully merging this pull request may close these issues.

2 participants