Back to questionsWhich types does TypeScript infer for
JuniorTheoryCommon
Which types does TypeScript infer for mode and for theme?
let mode = "dark";
const theme = "dark";string and "dark"
- Expecting
"dark"formodetoo: aletmay get a new value later, so TypeScript widens the literal type"dark"tostring. - Expecting
stringfortheme: aconstnever gets a new value, so TypeScript keeps the exact literal type"dark".
- Which type does
let copy = theme;get, and why? - Why does
const point = { x: 5 }give the propertyxthe typenumber?