TypeScript · Senior · Question 26 of 75

Why is Record<Status, string> more useful than { [k: string]: string } for a dictionary keyed by status?

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.

Further reading

Problem with a question

TypeScript · Senior · question 26

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz