Skip to content

CodeNot attempted

Type challenge: on* handler props

Difficulty: medium

Write HandlerProps<Events>, which turns { click: MouseEvent; keyDown: KeyboardEvent } into optional onClick / onKeyDown handler props. Hint: key remapping (as), a template literal, and Capitalize.

Show reference solution
// `& string` drops number/symbol keys so they can go into a template literal.
export type HandlerProps<Events> = {
[K in keyof Events & string as `on${Capitalize<K>}`]?: (event: Events[K]) => void;
};
Loading editor…