Be honest about an unchecked value
An API response, imported file or caught exception may not have the shape your component expects. The unknown type records that uncertainty and requires a check before meaningful use. The any type allows operations without those checks. Both can appear at integration boundaries, but letting any spread into ordinary application code removes useful feedback exactly where unfamiliar data is entering the system.
Narrow a concrete import result
Imagine a settings importer that receives unknown. First confirm the value is a non-null object, then verify the fields the feature requires. A name should be a string, enabled should be a boolean, and tags should be an array whose entries are supported strings. Return a new internal settings object after validation instead of asserting that the original value already satisfies the contract.
Handle thrown values deliberately
JavaScript code can throw values that are not Error instances. In a catch path, check whether the value is an Error before reading message. Provide a useful fallback for other cases, while keeping diagnostic handling separate from user-facing text. Do not cast every caught value to Error merely to satisfy the compiler; that assertion changes no runtime behavior.
Keep checks close to the boundary
Once external data has been validated, pass a trusted domain type through the rest of the feature. Rechecking unknown fields in every visual component makes rendering noisy and leaves uncertainty distributed across the codebase. A parser or adapter can explain both the accepted shape and how failures are reported, making future integration changes easier to isolate.
Use assertions only with an explanation
Some platform integrations require a type assertion because the compiler cannot express information you have already established. Keep those assertions narrow and document the evidence. An assertion should not be a shortcut around a missing runtime check for untrusted input. If the same assertion appears repeatedly, a typed wrapper or reusable validation function is often a clearer boundary.
Verify malformed inputs as well as types
Pass null, a primitive, an array, missing fields and fields with the wrong types into the adapter. Ensure the caller receives a specific failure rather than a later rendering exception. Run the compiler to catch unchecked property access. The goal is not eliminating every occurrence of any by force; it is preserving useful guarantees after the application has established what the data actually contains.
Further reading
Put the idea to work.
Explore free browser tools for images, text and developer workflows.