0Pricing
TypeScript Academy · Lesson

unknown vs any: The Safer Choice

Learn why unknown forces you to check types before use.

Welcome

TypeScript 3.0 introduced the `unknown` type as a type-safe alternative to `any`. In this lesson you'll learn what makes `unknown` safer and when to use it.

The Problem with any

With `any`, TypeScript turns off all checks. You can call methods, access properties, and assign to typed variables without restriction — and without safety.
let val: any = getData();
val.someMethod(); // TypeScript: OK. Runtime: possible crash

All lessons in this course

  1. Primitive Types: string, number, boolean
  2. The any Type and Why to Avoid It
  3. unknown vs any: The Safer Choice
  4. null, undefined, and Strict Null Checks
← Back to TypeScript Academy