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