TypeScript · Junior · Question 20 of 75

What does keyof { id: number; name: string } return?

Explanation

keyof returns a union of a type's keys. Value types are obtained via indexed access: T['id'] or T[keyof T]. keyof doesn't exist at runtime - use Object.keys for an array of keys.

Further reading

Problem with a question

TypeScript · Junior · question 20

Test yourself

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

Take this quiz