TypeScript · Junior · Question 38 of 75
How do you describe an object with arbitrary string keys and number values using an index signature?
- ✓Correct answer:
{ [key: string]: number } - 2
{ key: string => number } - 3
{ *: number }
Explanation
An index signature describes a "dictionary". The equivalent is Record<string, number>. With the noUncheckedIndexedAccess flag, obj[key] returns number | undefined, which better reflects reality.