Loading lesson…
TypeScript is JavaScript with types. Learn how `strict` mode catches bugs at compile time and how AI writes cleaner types than you might alone.
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.
// 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 stringInference handles most types. You only annotate function signatures and tricky variables.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";
}
}Union of string literals plus a switch gives exhaustive checks. Add a new status and TS tells you where to update.The big idea: turn on strict, annotate the boundaries, and let unions model real-world states. AI reads types better than comments.
15 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-progx-ts-fundamentals-builders
What is the main benefit of TypeScript over plain JavaScript?
What does it mean when someone says TypeScript 'fails early'?
Which TypeScript setting helps catch the most bugs during development?
Where should you manually add type annotations in TypeScript?
What does TypeScript 'inference' do?
Why should you avoid using the `any` type in TypeScript?
If you need to accept any value but still check its type, what should you use instead of `any`?
What is a union type in TypeScript?
Why are union types useful for modeling real-world situations?
What is a literal type in TypeScript?
What does type narrowing mean?
The lesson mentions that AI reads types better than comments. What does this suggest about AI-assisted coding?
What happens when TypeScript compiles code with type errors in strict mode?
Why would you choose `unknown` over `any` when handling external data?
What is the relationship between TypeScript and JavaScript?