What Is TypeScript and Should You Use It?
TypeScript adds a safety net to JavaScript — catching mistakes before your code ever runs.
JavaScript with a Seatbelt
TypeScript is a version of JavaScript — the language that makes websites interactive — but with one important addition: it watches your back. When you write code in regular JavaScript, mistakes like typos or using the wrong type of data only show up when you run the program. TypeScript catches those mistakes before you run anything.
Think of it like spell-check for your code. Just like a word processor catches spelling errors as you type, TypeScript catches code errors as you write. This means fewer bugs making it to your actual website or app.
TypeScript was created by Microsoft and is used by big companies like Google, Airbnb, and Slack. It is free and open source — anyone can use it.
Fewer Surprises, Less Debugging
When you write code without TypeScript, you might not notice a problem until a user clicks something and your page breaks. With TypeScript, your computer tells you right away if something looks wrong.
This matters even more when you're working with AI coding tools. When an AI writes code for you, it can make small mistakes — like using a number where it expected text. TypeScript catches those mistakes instantly, so you're not chasing phantom bugs.
💡 Key Insight
If you're using vibe coding with AI tools, TypeScript is your safety net. It catches the small errors AI might make, so you spend less time debugging and more time building.
Types: The Core Idea
The word "Type" in TypeScript comes from a simple idea: every piece of data in your code has a type. A type is just what kind of thing it is — a number, a word, a true/false value, and so on.
Here's a quick example. In regular JavaScript, you could write:
let name = "Alex" let age = 25 // JavaScript won't complain if you do this: name = age // Now name holds the number 25, not "Alex"
JavaScript lets this happen without complaining. TypeScript, on the other hand, would flag this and say: "Hey, you said name should be text — don't put a number in it!"
You tell TypeScript what type each piece of data should be. Then it watches everything you write and warns you if something doesn't match up.
let name: string = "Alex" let age: number = 25 // TypeScript says: "Error! name must be a string." name = age // This would show a red warning
The : string and : number parts are called type annotations — little labels that tell TypeScript what to expect.
A Simple User Card
Here's a practical example: building a small function that shows a user's name and age. First, in regular JavaScript:
function showUser(name, age) { console.log("User:", name, "Age:", age) } showUser("Jordan", "twenty") // Works! But age is wrong type
Now the TypeScript version with type safety:
function showUser(name: string, age: number): void { console.log("User:", name, "Age:", age) } // This line will show an error before you even run it: showUser("Jordan", "twenty") // ^^^^^^ Error: expected number, got string!
See that line age: number? That's TypeScript saying "age must be a number." When you try to pass "twenty" (text) instead of 20 (a number), TypeScript catches it immediately — even if you've never run the code yet.
Knowledge Check
Test what you learned with this quick quiz.
Quick Quiz — 3 Questions
: string after a variable name?