Interview practice question
Typing an event emitter with known events
Frontend Engineering · TypeScript · Intermediate
How would you type an event emitter so event names and payloads are checked?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- Event map type: { userCreated: User; ... }.
- Generic on<K extends keyof Events>(event: K, handler: (p: Events[K]) => void).
- emit typed similarly.
- Autocomplete and safety.
- Reusable generic class.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.