Created
March 7, 2025 21:49
-
-
Save roginfarrer/b440b9941017e6c07005f960dfbb83cb to your computer and use it in GitHub Desktop.
Web Component Props
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Props derived from custom element class. Currently has limitations of making | |
// all properties optional and also surfaces life cycle methods in autocomplete. | |
// TODO(augustjk) Consider omitting keyof LitElement to remove "internal" | |
// lifecycle methods or allow user to explicitly provide props. | |
type ElementProps<I> = Partial<Omit<I, keyof HTMLElement | "events">>; | |
type WebComponentProps<I extends HTMLElement> = React.DetailedHTMLProps< | |
React.HTMLAttributes<I>, | |
I | |
> & | |
ElementProps<I>; | |
type ClassStaticMembers<T> = { | |
[Key in keyof T as Key extends "prototype" ? never : Key]: T[Key]; | |
}; | |
declare abstract class EventDef { | |
public readonly events: Record<string, Event>; | |
} | |
type ElementEvents<I extends EventDef> = { | |
[k in keyof I["events"] as `on${string & k}`]: (event: I["events"][k]) => void; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment