From be8ee0198f9b015f09fa8f38ab480c163c0ca6f7 Mon Sep 17 00:00:00 2001 From: Buddy Date: Tue, 10 Nov 2026 09:59:09 -0800 Subject: [PATCH] Add typed events map: true, listener options, listen(), or custom() events maps a name to true, listener options, listen(options?) for an explicit event type, or custom(options?) for a CustomEvent (the same as listen>()). Otherwise an event is typed from HTMLElementEventMap by name. The array form is gone. handleEvent gets HandledEvent, each event tagged with its literal type so event.type narrows. --- README.md | 3 +- src/events.ts | 111 +++++++++++++++++++++++++++++++++++++ src/index.ts | 10 ++++ src/types.ts | 20 +++---- src/web-component.ts | 7 ++- test/types.test-d.ts | 61 +++++++++++++++++++- test/web-component.test.ts | 33 ++++++++++- 7 files changed, 226 insertions(+), 19 deletions(-) create mode 100644 src/events.ts diff --git a/README.md b/README.md index 2e014be..4248235 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ const SPEC = { shadow: 'open', // omit for light DOM template: '', css: ':host { display: block; }', - events: ['click'], + events: { click: true }, element: { input: 'input.name', // refs.input: HTMLInputElement | null (from the tag) thing: '.thing', // refs.thing: Element | null (no tag to go on) @@ -47,6 +47,7 @@ ExampleElement.observedAttributes; // readonly ('user-id' | 'min' | 'is-ready' | - **Light DOM**: `template` is appended on first connect; `css` is added once per element type, as a `