TypeScript · Generics · Tech Lead · Architecture
Design a type-safe event emitter with generics.
Short Interview Answer
Map event names to payload types; on/emit constrained by keyof map.
Detailed Explanation
Prevents wrong payload types. Consider once/off and async handlers.
Example
type Events = { login: { userId: string }; logout: void };
// emit('login', { userId }) ok; emit('login', 1) error