Module 1 · TypeScript · Type Safety

The Red
Squiggle

Types catch the bug before you press run — you see it instantly in VS Code

TypeScript Type error VS Code formatPrice
AI with Rufat
PROBLEM — no types

JavaScript: Error Only at Runtime

// JavaScript — no types, the bug hides
function formatPrice(price) {
return `$${price.toFixed(2)}`;
}
formatPrice('not-a-number'); // 💥 crashes at runtime
The editor says nothing. The crash happens only when you run the code — sometimes in front of a user.
AI with Rufat
FIX — type annotation

TypeScript: Error Right in the Editor

TS formatPrice.ts
1
2
3
4
5
function formatPrice(price: number): string { return `$${price.toFixed(2)}`; } formatPrice('not-a-number');
⚠ Argument of type 'string' is not assignable to parameter of type 'number'. ts(2345)
AI with Rufat
🟥

Rule:
Fix the Red Line Before You Run

That red squiggle is the lesson. Types catch the bug in the editor, not at runtime.

🔤
Add the annotation
Write price: number — the editor guards you
📐
Then reach for interfaces
Describe the shape of your test data
🎯
In Module 2
Typed locators and Page Objects
AI with Rufat
← / → · space