TypeScript · Junior · Question 21 of 75
What does typeof do in a type position: type Config = typeof config?
- ✓Correct answer: Takes the type of the
configvariable inferred by the compiler - 2Returns the string
'object', as in JavaScript - 3Checks the type of
configat runtime
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.