The `unknown` Type
This lesson explains the `unknown` type and explains how it is a better alternative to using `any`.
Overview
When trying to eliminate any from your codebase, it’s useful to know about the unknown type. It is a safer alternative to any. Both any and unknown represent an unknown type. However, there is a key difference between these two:
- all types are assignable to the anytype and theanytype is assignable to any other type
- all types are assignable to the unknowntype, but theunknowntype is not assignable to any type
Type assignability
What does it mean when a type is assignable to another type? We say that type A is assignable to type B if you ...