What is TypeScript?
Why TypeScript exists, what the compiler actually does, and what happens to types at runtime.
It's 2 AM and production is down. The bug? Someone passed a user object to a function that expected a user ID:
// JavaScript happily runs this…
function getOrders(userId) {
return fetch('/api/orders?user=' + userId);
}
getOrders(currentUser); // oops — sent [object Object] to the APIJavaScript only finds this at runtime — in front of your users. TypeScript finds it at compile time — in your editor, before the code ever ships:
function getOrders(userId: string) { /* … */ }
getOrders(currentUser);
// ❌ Argument of type 'User' is not assignable to parameter of type 'string'TypeScript = JavaScript + a static type checker. The pipeline:
1. You write .ts files — normal JavaScript plus type annotations
2. The compiler (tsc) checks every value against its declared type
3. If the checks pass, it erases all the types and emits plain .js
4. The browser or Node runs that plain JavaScript — types never exist at runtime
// input.ts
const greet = (name: string): string => `Hello, ${name}`;
// output.js — types are gone, nothing else changed
const greet = (name) => `Hello, ${name}`;- Type erasure is the single most important fact in this whole course
What happens to type annotations when TypeScript compiles to JavaScript?
- AThey are converted into runtime checks that throw errors
- BThey are completely erased — the emitted JavaScript has no types
- CThey are stored in a separate metadata file the browser reads
- DThey become comments in the JavaScript output
A crucial property: TypeScript is a superset of JavaScript. Every valid JavaScript program is already valid TypeScript. You can rename app.js to app.ts and start adding types gradually — file by file, function by function.
This is why TypeScript won: teams migrate incrementally instead of rewriting. Today it's the default for serious JavaScript work — React, Node APIs, VS Code itself (1.5 million lines of TypeScript).
This TypeScript has a type error. What happens at runtime if you force it to compile anyway (the emitted JS still runs)?
function double(n: number) {
return n * 2;
}
// @ts-ignore — suppress the compile error
console.log(double("5"));- A10
- B55
- CTypeError is thrown
- Dundefined
TypeScript checks your code at _____ time, not at runtime.
What you'll build up through this course:
- Foundations — annotations, inference, and compiler configuration
- Everyday types — arrays, objects, unions, functions,
anyvsunknown - Narrowing — how TypeScript follows your
ifstatements to refine types - Object types — interfaces,
readonly, index signatures, intersections - Generics — writing code that is flexible and type-safe
- Advanced types —
keyof, utility types, mapped and conditional types - Production patterns — classes, and safely typing data from APIs
Everything assumes you already know JavaScript — this course is about the type layer on top.