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 crashAll lessons in this course
- Primitive Types: string, number, boolean
- The any Type and Why to Avoid It
- unknown vs any: The Safer Choice
- null, undefined, and Strict Null Checks