Designs complex generic types, refactors `any` types to strict alternatives, creates type guards and utility types, and resolves TypeScript compiler errors. Use when the user asks about TypeScript (TS) types, generics, type inference, type guards, removing `any` types, strict typing, type errors, `infer`, `extends`, conditional types, mapped types, template literal types, branded/opaque types, or utility types like `Partial`, `Record`, `ReturnType`, and `Awaited`.
87
95%
Does it follow best practices?
Impact
76%
1.16xAverage score across 5 eval scenarios
Passed
No known issues
A React-like UI framework team is building an internal event system that needs to be genuinely type-safe across two dimensions. First, they want an event registry where adding a new event automatically derives the corresponding handler type map — so that onClick is always typed as (e: MouseEvent) => void and onKeyDown as (e: KeyboardEvent) => void, derived entirely from the registry rather than maintained manually. Second, the system needs to handle event lifecycle states (pending, dispatching, handled, cancelled) with a state machine that TypeScript can verify is exhaustive — if a new lifecycle state is added to the code, any switch statement that doesn't handle it should fail to compile.
The team also wants to make sure that the system's internal async dispatch loop handles type narrowing correctly given that narrowed types can sometimes reset inside callbacks.
Produce the following files:
event-system.ts — the event registry type infrastructure, handler map derivation, and lifecycle state machinetype-tests.ts — compile-time tests verifying:
DESIGN.md — a short explanation covering: how the handler map type is derived from the registry, how the lifecycle state machine ensures all states are handled at the type level, and any considerations around type narrowing inside the async dispatch loop