What is the ‘unknown’ type in TypeScript and how does it differ from ‘any’?

TypeScript Associate Medium

TypeScript Associate — Medium

What is the ‘unknown’ type in TypeScript and how does it differ from ‘any’?

Key points

  • 'unknown' enforces type narrowing for safety
  • 'any' allows any type without restrictions
  • 'unknown' promotes type safety
  • 'any' sacrifices type safety for flexibility

Ready to go further?

Related questions