I want to write a generic addListener function that works with any EventTarget. I'd like to infer the callback function's parameters using the event emitter's types and the event name, similar to how addEventListener works.
Essentially, I want this code to work without using any:
addListener(element, 'click', (event) => {
// event is automatically inferred to be `MouseEvent`
...
});
My use case is that I want to polyfill event target options like once and signal onto Node EventEmitters, which have a similar shape to EventTarget. I'm asking the question about EventTarget since it has built-in examples and our EventEmitter types are custom.