Skip to content

3.0.0

Latest
Compare
Choose a tag to compare
@alexreardon alexreardon released this 26 Apr 23:14

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 😁
Screenshot 2023-04-26 at 4 11 22 pm Screenshot 2023-04-26 at 4 08 26 pm
Screenshot 2023-04-27 at 8 41 49 am Screenshot 2023-04-27 at 8 42 34 am

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

Other

  • Improved clarity of readme #101
  • Bumping dev dependencies #99
  • Moved repo to TypeScript@5 #99
  • Type check tests will now run as a part of the build #99