@battle-racing/br-common-lib
Version:
Common library for all Battle Racing Repositorios
17 lines (15 loc) • 722 B
text/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;
//With Extra
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>;
};