Record Type
Predict Output Easy
Question
What does this code print?
Code
type R = Record<string, number>;
const obj: R = { a: 1, b: 2, c: 3 };
console.log(obj.a + obj.b + obj.c);
Hint
Record<string, number> creates an object with string keys and number values.
Explanation
Record<string, number> is equivalent to { [key: string]: number }. The object { a: 1, b: 2, c: 3 } is valid. 1 + 2 + 3 = 6.
Related Resources
Related Lessons
- Utility Types
Learn utility types.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.