TypeScript · Senior · Question 49 of 75
What does T[keyof T] return for T = { a: string; b: number }?
- ✓Correct answer:
string | number - 2
'a' | 'b' - 3
{ a: string } | { b: number }
Explanation
Indexed access by a union of keys gives a union of value types. It's often used to get the union of a constant object's values: typeof obj[keyof typeof obj].