TypeScript · Senior · Question 26 of 75
Why is Record<Status, string> more useful than { [k: string]: string } for a dictionary keyed by status?
- ✓Correct answer: The compiler requires a key for every status
- 2An index signature doesn't support string values
- 3
Recordcompiles to aMapand runs faster
Explanation
Add a new member to the Status union, and every Record<Status, ...> stops compiling until you add a translation, an icon and so on. An index signature accepts any string and doesn't guarantee completeness.