From JavaScript to TypeScript — Phase 2

javascript dev.to

Understanding the TypeScript Mental Model

Many developers struggle with TypeScript not because it is hard — but because they misunderstand what it actually is.

Let’s fix that first.

TypeScript Is Not a Runtime Language

TypeScript does not run in production.
It compiles into JavaScript.

TypeScript → Compiler → JavaScript → Runtime
Enter fullscreen mode Exit fullscreen mode

Types exist only during development.

The Core Idea

TypeScript adds static analysis to JavaScript.
Its job is to answer:

“Can this code break before we run it?”

1. Type Annotations

let age: number = 30;

You describe expected values.

2. Function Types

function add(a: number, b: number): number {
return a + b;
}

Think of this as a contract.

3. Interfaces (The Most Important Concept)

interface User {
id: number;
name: string;
}

Interfaces describe data shape — not behavior.
Most real TypeScript usage revolves around this idea.

4. Type Inference

You usually don’t write types manually.

const name = "Ali";

TypeScript already knows it’s a string.
Good developers rely on inference.

5. Types vs Interfaces

Simple rule:

Interface → objects and models
Type → unions and compositions

Mental Shift

Stop asking:

How do I type everything?

Start asking:

Where does type safety provide real value?

Next: learning the small set of TypeScript features that give massive power.

Source: dev.to

arrow_back Back to Tutorials