If I try to exactly recreate the type of another function using (...args: Parameters<OtherFn>) => void the types do not match. Why is this?
I want this functionality in a type safe EventEmitter class:
type EventEmitterEvents = Record<string, (...args: any[]) => void>;
export class EventEmitter<Events extends EventEmitterEvents> {
/* ... */
once<Event extends keyof Events>(event: Event, listener?: Events[Event]): Promise<Parameters<Events[Event]>> {
return new Promise(resolve => {
let self = this;
function listenWrapper(this: any, ...args: Parameters<Events[Event]>) {
if (listener)
listener.apply(this, args);
self.off(event, listenWrapper);
resolve(args);
}
this.on(event, listenWrapper);
});
}
```but `listenWrapper` does not match the type `Events[Event]`.
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.