Skip to content

Instantly share code, notes, and snippets.

@1natsu172
Created March 16, 2019 11:23
Show Gist options
  • Save 1natsu172/dc52e9f78b1b7189518fafa9985f616d to your computer and use it in GitHub Desktop.
Save 1natsu172/dc52e9f78b1b7189518fafa9985f616d to your computer and use it in GitHub Desktop.
The interface of HTMLElement's event type and event handler
/* eslint-disable @typescript-eslint/no-explicit-any */
export type HTMLElementEventHandlers<U extends keyof HTMLElementEventMap> = {
[K in U]: (event: HTMLElementEventMap[K]) => any
}
@1natsu172
Copy link
Author

example 👨‍💻

const events: HTMLElementEventHandlers = {
  touchstart: (event: TouchEvent) => console.log(event),
  touchmove: (event: TouchEvent) => console.log(event),
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment