Write EventHandlers<T>: from an event map like { click: Point }, build optional onClick-style handler props.
An event map's keys are event names, and its values are the payload types. EventHandlers<T> has an optional property for each event, named on followed by the capitalized event name, taking that event's payload. Also write handlerName(event), which returns that name, typed as the literal: handlerName("click") returns "onClick", typed "onClick".
type EventHandlers<T> = Record<string, (payload: unknown) => void>; function handlerName(event: string): string { return event;} // type AppEvents = { click: { x: number; y: number }; close: void };// EventHandlers<AppEvents>// // { onClick?: (payload: { x: number; y: number }) => void; onClose?: (payload: void) => void }The answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…