Closed ehaynes99 closed 2 years ago
Good point, indeed! Will check out #23.
Btw, why did you delete the section about using the Parameters<>
util type? I found that to be very valid argument. In fact, I couldn't believe that this type has been around since TS 3.1 (!) and I didn't take notice! š
When I wrote that part, I didn't notice that the Arguments
type is exported by the library, so it would be a breaking change to remove it. However unlikely, someone could be using:
import { Arguments } from 'typed-emitter';
type OddType = Arguments<5>; // equivalent to `type OddType = [5];`
I'm happy to open an issue/PR for that as well, but semver patterns would dictate a major version 2 for it. Since the additional constraints on Events
would already ensure that it's only ever used with functions, I figured it would be better to minimize the impact.
Well, constraining the event listeners type is a breaking change, anyway, so I wouldn't care too much š
Fair enough. I added another commit to #23
Currently, the generic type for
Events
is unconstrained. Example:This results in a type that expands to:
This could be done like:
In addition to preventing improper usage, this would allow stronger typing for
rawListeners
andlisteners
, which currently return untypedFunction[]
.