AI Hints
Home›TypeScript Tutorial›Testing, Migrating, Mistakes
TypeScript · Lesson 96 of 120

Common Mistakes

And fixes.

⏱ 2 min read▶ Video at 1:15:07🎓 Free
Watch this lesson in the TypeScript courseWatch on YouTube ↗Full TypeScript course

Let's look at the mistakes almost everyone makes when learning TypeScript. Knowing them early saves a lot of confusion.

Common Mistakes
From the video: Common Mistakes
  • Everyone makes them
  • Learn early
  • Save confusion

Mistakes and fixes

Using any switches off checking, use unknown. Assertions hide bugs, validate instead. Types vanish at runtime, so check outside data. Over complicated types confuse everyone, keep them simple. And turning strict off hides real problems.

MistakeFix
any everywhereunknown + narrowing
as on outside datavalidate (Zod)
Thinking types runruntime checks
Clever typessimple types
strict offstrict on

A good habit

When the compiler complains, read the whole message, and ask what it's protecting you from. Usually, it has found a real bug.

keyvalue
Readthe whole message
Askwhat's it protecting?
Usuallya real bug
Don'tsilence it with any

Summary

Avoid any, avoid assertions on outside data, and keep strict on. Next, the project.

Key takeaways
  • No any
  • Validate
  • Strict
Next up: Project: The Plan — an orders library