TypeScript · Junior · Question 21 of 75

What does typeof do in a type position: type Config = typeof config?

Explanation

In expressions, typeof is the JS operator that returns a string. In a type position, it's a TypeScript operator that extracts a value's type. Handy for avoiding duplication: const routes = {...} as const; type Routes = typeof routes.

Further reading

Problem with a question

TypeScript · Junior · question 21

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