@battle-racing/br-common-lib
Version:
Common library for all Battle Racing Repositorios
11 lines (10 loc) • 683 B
TypeScript
/** Map the Events Params Types to Event to be used on Socket.io */
export type EmptyEventParams = () => void;
export type EventParams<EventParams> = (payload: EventParams) => void;
export type EmptyEventParamsWithExtra<Extra> = (params: Extra) => void;
export type EventParamsWithExtra<EventParams, Extra> = (params: Extra & {
payload: EventParams;
}) => void;
export type SocketParamsToEvents<Event, Extra = undefined> = {
[EventKey in keyof Event]: Event[EventKey] extends undefined ? Extra extends undefined ? EmptyEventParams : EmptyEventParamsWithExtra<Extra> : Extra extends undefined ? EventParams<Event[EventKey]> : EventParamsWithExtra<Event[EventKey], Extra>;
};