You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+59
Original file line number
Diff line number
Diff line change
@@ -191,6 +191,65 @@ input.dispatchEvent(
191
191
);
192
192
```
193
193
194
+
## Adding TypeScript typed events
195
+
196
+
If you're using TypeScript, you can maintain a list of custom event names that map to their specific types, making it easier to write type-safe code while using delegated events. Add the following snippet to a `.d.ts` file in your local project and alter the contents of `CustomEventMap` to list all the well-known events in your project:
197
+
198
+
```typescript
199
+
// events.d.ts
200
+
interfaceCustomEventMap {
201
+
'my-event:foo': {
202
+
something:boolean
203
+
}
204
+
// When adding a new custom event to your code, add the event.name + event.detail type to this map!
0 commit comments