$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #195

Which fix removes the bug?

const handlers: Record<string, () => void> = {};
handlers[key]();
  1. Check the key exists
  2. Type key as string
  3. Use a Map instead
  4. Add a default handler
Record claims every string key is present, so a missing entry throws only at runtime.
Play Problem Solving ▸