CodePark/ questions / Basics & inference
START PRACTICINGPRACTICE
Frontend question · TypeScript › Basics & inference

What is the type of config.mode?

const config = { mode: "dark", retries: 3 };
string

The answer is string. The const only stops you from assigning a new object to config. Its properties can still change, so TypeScript widens the literal "dark" to string.

The tempting answer
"dark" is wrong here. You get "dark" only if you add as const or write an explicit type.