My TypeScript code parses messages from a device: const msg = JSON.parse(text); and then reads msg.payload.temp.toFixed(1). It compiles without complaint and then crashes at run time with "Cannot read properties of undefined" when the device sends an error message with a different shape. The linter suggests replacing any with unknown, but then every property access becomes a compile error.
What is the practical difference between the two types, and how am I supposed to get from unknown to a usable typed object without casting everything?




