Search⌘ K

Review: Type System and Type Errors

Explore how TypeScript's type system works, including inference, annotations, and assertions. Learn to identify and fix common type errors, enhancing your code safety and confidence by understanding how TypeScript detects issues before runtime.

We’ve covered a lot of ground—and this is where it all starts to click.

So far, we’ve built a good understanding of how TypeScript thinks: how it infers types, when it needs our help, and how it catches the bugs we’d rather not meet in production. This review is our moment to step back, connect the dots, and lock it in.

It’s about internalization. We want to make the type system feel like second nature.

The engine behind the scenes: Inference

TypeScript doesn’t need us to annotate everything. Most of the time, it can figure things out just fine:

TypeScript 5.8.3
let score = 100; // inferred as number
const theme = "dark"; // inferred as the literal "dark"

But inference has limits. If we declare a variable without an initializer or with something vague like null—TypeScript has no clue what we mean. That’s when it falls back to any—the type that disables all checking and turns TypeScript into plain JavaScript.

To keep our code safe:

  • Initialize variables with meaningful values.

  • Use const ...