I have an interface, IHubServerResponse which is an interface of just functions. I won't post the full thing but I've added a screenshot with a sample. I have a waitFor function which will make a promise and wait for that signal to come in, and I have it setup so it requires an equally typed function relative to the signal it's waiting for. The problem is that the spread operator doesn't work (A spread argument must either have a tuple type or be passed to a rest parameter.), so it passes it in as a list. How do I do this?
waitFor<K extends keyof IHubServerResponse>(type: K): Promise<Parameters<IHubServerResponse[K]>> {
return new Promise((resolve) => {
const callback = ((...args: Parameters<IHubServerResponse[K]>) => {
this.unsubscribe(type, callback);
resolve(args); // Spread doesn't work here
}) as IHubServerResponse[K];
this.subscribe(type, callback);
});
}```