DEV Community

Cover image for TypeScript Survival Guide (Part 2): Start Thinking in TypeScript
Noriuki
Noriuki

Posted on

TypeScript Survival Guide (Part 2): Start Thinking in TypeScript

In Part 1, we covered the most common mistakes.

Now it’s time to shift how you think.

Because TypeScript is not just about adding types —
it’s about designing your code better.


1. Stop thinking in variables — think in models

Beginners often focus on typing variables:

let name: string = "John"
Enter fullscreen mode Exit fullscreen mode

But real TypeScript starts when you model your data:

type User = {
  name: string
  age: number
}
Enter fullscreen mode Exit fullscreen mode

Now you're not just typing values —
you're defining structures.

This makes your code easier to understand and reuse.


2. Model states, not just data

One of the biggest mindset shifts is modeling possibilities.

type Status = "loading" | "success" | "error"
Enter fullscreen mode Exit fullscreen mode

This is powerful because:

  • it limits what can happen
  • it documents your logic
  • it prevents invalid states

Instead of asking:
“what values can this have?”

You already know the answer.


3. Let types guide your code

In JavaScript, you write code first and figure things out later.

In TypeScript, types help guide your implementation.

function createUser(user: User) {
  // your code here
}
Enter fullscreen mode Exit fullscreen mode

Before writing logic, you already know:

  • what you receive
  • what shape it has
  • what is allowed

Types become a form of design.


4. Reduce ambiguity as early as possible

Good TypeScript is not about adding more types.

It’s about removing uncertainty.

Bad:

function process(data: any) {
  // unclear
}
Enter fullscreen mode Exit fullscreen mode

Better:

function process(user: User) {
  // clear and predictable
}
Enter fullscreen mode Exit fullscreen mode

The earlier you define structure,
the fewer problems you have later.


5. Think in constraints, not freedom

JavaScript gives you freedom.

TypeScript gives you boundaries.

And that’s a good thing.

Constraints:

  • prevent invalid states
  • guide other developers
  • make refactoring safer

The goal is not to allow everything —
it’s to allow only what makes sense.


Final thoughts

Once you start thinking in types:

You stop guessing.
You stop overchecking.
You start building with intention.

And that’s when TypeScript really clicks.

Top comments (0)