TypeScript · Middle · Question 25 of 75

How do object, {} and Record<string, unknown> differ as types?

Explanation

{} accepts strings and numbers too - everything except null and undefined, which often surprises people. object excludes primitives. Record<string, unknown> is an object with arbitrary string keys whose values you can access. For "any value", unknown is better.

Further reading

Problem with a question

TypeScript · Middle · question 25

Test yourself

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

Take this quiz