Using the unknown type
Understand how to use TypeScript's unknown type to create safer, strongly-typed code when handling uncertain values. Learn to perform explicit type checks and use type predicates for secure data operations, reducing reliance on any and improving code reliability.
We'll cover the following...
We'll cover the following...
An any type refresher
We learned from a previous lesson that the any type could be used when we are unsure of the type of value. The problem with any is that no type checks will be carried out on values of type any.
What if there was a type like any that can be used for values we don’t know but was also type-safe? This is what the unknown type is!