Skip to content

Instantly share code, notes, and snippets.

@guiseek
Created December 9, 2023 06:46
Show Gist options
  • Save guiseek/c223b3cfb73825959e5e46dd921d7230 to your computer and use it in GitHub Desktop.
Save guiseek/c223b3cfb73825959e5e46dd921d7230 to your computer and use it in GitHub Desktop.
Custom element extend eecorator
interface CustomConstructor<K extends keyof HTMLElementTagNameMap>
extends CustomElementConstructor {
new (...params: any[]): HTMLElementTagNameMap[K]
prototype: HTMLElementTagNameMap[K]
}
export const extend = <K extends keyof HTMLElementTagNameMap>(inherite: K) => {
return <T extends CustomConstructor<K>>(target: T) => {
customElements.define(`txs-${inherite}`, target, {extends: inherite})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment