andywer / andywer/typed-emitter
Type issue with listener parameters
Open
- Dominant language
- JavaScript
- Stars
- 285
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
I have an variable called "event" and it is type is `keyof Events`
```ts
// I have an variable called "event" and it's type is `keyof Events`
emitter.on(event, (...args) => {
// It says args is any[] but we know that it is parameter of any of Events
})
```
To fix this we can change type definitions.
Current type definition is:
```ts
on (event: E, listener: Events[E]): this
```
but if we change it with
```ts
on(event: E, listener: (...args: Parameters) => ReturnType): this
```
the problem gets solved, now TypeScript knows args is any of the Events
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.