3.8 unknown: The Type-Safe Alternative to any
Alright, let’s talk about any’s smarter, more responsible cousin: unknown. If any is the developer who hacks everything together with duct tape and a prayer, unknown is the one who actually reads the instruction manual first. It’s a core tool for writing type-safe code, especially when you’re dealing with data from the outside world, like API responses, user input, or file contents—places where the type isn’t guaranteed. Here’s the fundamental truth about unknown: you can assign anything to a variable of type unknown. A string, a number, a complex object, a Promise of a bag of chips—whatever. It’s the “top type” in the type system, meaning every other type can be assigned to it. This is its superpower and its initial frustration.