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 any type and the any type is assignable to any other type
  • all types are assignable to the unknown type, but the unknown type is not assignable to any type

Get hands-on with 1200+ tech skills courses.