Lesson 153 of 1570
TypeScript Fundamentals With AI
TypeScript is JavaScript with types. Learn how `strict` mode catches bugs at compile time and how AI writes cleaner types than you might alone.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1Types Are a Conversation With Your Future Self
- 2types
- 3strict mode
- 4inference
Concept cluster
Terms to connect while reading
Section 1
Types Are a Conversation With Your Future Self
A type says: this variable will hold a string, not a number. The compiler checks every line to see if you kept that promise. When you do not, it fails early instead of at 2am.
Inference handles most types. You only annotate function signatures and tricky variables.
// Always start with strict mode in tsconfig.json
// { "compilerOptions": { "strict": true, "target": "ES2022" } }
function greet(name: string, loud = false): string {
const msg = `Hello, ${name}!`;
return loud ? msg.toUpperCase() : msg;
}
console.log(greet("Ada"));
console.log(greet("Bo", true));
// greet(42); // compile error: number is not stringUnion types are everywhere
Union of string literals plus a switch gives exhaustive checks. Add a new status and TS tells you where to update.
type Status = "idle" | "loading" | "error" | "success";
function label(s: Status): string {
switch (s) {
case "idle": return "Ready";
case "loading": return "Working...";
case "error": return "Try again";
case "success": return "Done";
}
}Key terms in this lesson
The big idea: turn on strict, annotate the boundaries, and let unions model real-world states. AI reads types better than comments.
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “TypeScript Fundamentals With AI”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Builders · 30 min
Python Variables & Types — With an AI Explainer Beside You
Variables are named boxes for data. You'll write your first ten, then use AI to decode error messages and grow your intuition for types.
Builders · 25 min
What Does AI-Assisted Coding Even Mean?
AI-assisted coding is not magic and not cheating. It is a new way of working where a model drafts, you decide. Let's draw a map before we start building.
Builders · 30 min
Your First Copilot-Style Completion
Let's actually feel what autocomplete is like. Write a comment, pause, and watch a full function appear. Then learn what to do next.
