Skip to content

Instantly share code, notes, and snippets.

@roginfarrer
Created March 7, 2025 21:49
Show Gist options
  • Save roginfarrer/b440b9941017e6c07005f960dfbb83cb to your computer and use it in GitHub Desktop.
Save roginfarrer/b440b9941017e6c07005f960dfbb83cb to your computer and use it in GitHub Desktop.
Web Component Props
// 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