I have some third party framework with functionality to add an event listener on the server and call that event from the client side.
That look like this for server:
framework.addEvent('myEvent1', (clientId, myParam1, myParam2...) => { my server work here })
And on client side:
let result = await framework.callRemote('myEvent1', myParam1, myParam2,...)
I do not understand how to correctly and conveniently describe the types of my events, their string names and associated callback types that I could use on the server and client sides (by importing these types from the global module).
Each callback on the server side always has a clientId as first argument, but next my parameters and their types may be different for each event.
I only came up this:
export namespace ServerEvent {
export enum Name {
MyEvent1 = 'MyEvent1',
MyEvent2 = 'MyEvent2',
MyEvent3 = 'MyEvent3',
}
export namespace Func {
export type MyEvent1 = (myArg1: string) => void
export type MyEvent2 = (myArg1: number, myArg2?: boolean) => void
export type MyEvent3 = () => void
}
}
But even this I don't understand how to use it to see all arguments and their types on server and client side.
I found some example of which perhaps solves my problem, but I cannot grasp it and how to move in this direction:
const wrapper = <U extends (...args: any[]) => any>(func: U) => (...args: Parameters<U>) : ReturnType<U> => func(...args);