A huge thank you to @Andarist for the TypeScript
improvements for bind-event-listener
that went into this release 👏
New: Autocomplete for event names
With TypeScript@5+ you can now get wonderful autocomplete for event names on EventTarget
's for bind
and bindAll
.
Before No auto complete for event names 😢 |
After Auto complete for event names 😁 |
---|---|
Change: As many correctly typed event listeners for bindAll
as you like
bindAll
previously supported correct typing on up to 12
event listeners. Now, bindAll
supports correct typing on as many event listeners as you like. To help facilitate this change, we have changed the type signature of bindAll
from taking strings, to taking an array of strings
- bindAll<HTMLElement, 'click', 'keydown'>(button, [/*bindings*/]);
+ bindAll<HTMLElement, ['click', 'keydown']>(button, [/*bindings*/]);
We generally recommend you don't provide the values for the bind
or bindAll
generics, and rather just let them be inferred.
import { bind, bindAll } from 'bind-event-listener';
const button = document.querySelector('button');
if (!button) {
return;
}
const unbind = bind(button, { type: 'click', listener(event) {} });
const unbindAll = bindAll(button, [
{ type: 'click', listener(event) {} },
{ type: 'keydown', listener(event) {} },
]);
💥 This change was listed as a breaking change as it changed the public type signature of
bindAll