TypeScript is a superset of JavaScript that adds static types. In simple language, it’s plain JS plus a type-checker that runs at build time. When we compile, TypeScript strips all the types away and gives us regular JavaScript that runs in any browser or Node.js.
So why bother? JS is dynamically typed — variables can hold anything, and we only find out we passed a string where a number was expected at runtime (usually in production at 2 AM). TS catches those mistakes while we type the code.
The three big wins:
- Catch bugs early. Typos, wrong argument types, missing properties — flagged before we run anything.
- Editor superpowers. Autocomplete actually knows what
user.can be. Refactors (rename a field) update every usage. - Self-documenting code. Types describe intent — we don’t need to read the function body to know what it returns.
Think of it like wearing a seatbelt. It doesn’t make us a better driver, but it prevents the silly accidents from being catastrophic.
// Plain JS — this compiles fine and crashes at runtime
function greet(name) {
return "Hello, " + name.toUpperCase();
}
greet(42); // 💥 name.toUpperCase is not a function
// TypeScript — caught at compile time
function greetTs(name: string): string {
return "Hello, " + name.toUpperCase();
}
greetTs(42); // ❌ Argument of type 'number' is not assignable to 'string'
The only difference is the : string annotations. That tiny addition gives us the safety.
How it actually runs
TS code never runs directly. The TypeScript compiler (tsc) checks types, then emits JS. Tools like ts-node, tsx, Vite, and Next.js wrap this so we don’t think about it.
npm install -D typescript
npx tsc --init # creates tsconfig.json
npx tsc # compiles .ts → .js
When NOT to use it
For tiny throwaway scripts or a 10-line demo, TS is overkill. But anything with a team, anything that ships to users, anything we’ll touch again in 6 months — types pay for themselves quickly.
Interview soundbite
“TypeScript is a static type-checker layered on JavaScript. Types exist at compile time only — the runtime is just JS. We get earlier bug detection and much better tooling, at the cost of a build step and a learning curve.”