I have an variable called "event" and it is type is keyof Events
// 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:
on<E extends keyof Events> (event: E, listener: Events[E]): this
but if we change it with
on<E extends keyof Events>(event: E, listener: (...args: Parameters<Events[E]>) => ReturnType<Events[E]>): this
the problem gets solved, now TypeScript knows args is any of the Events
I have an variable called "event" and it is type is
keyof Events
To fix this we can change type definitions. Current type definition is:
but if we change it with
the problem gets solved, now TypeScript knows args is any of the Events