What is TypeScript?
A statically typed superset of JavaScript that catches errors before your code runs.
2 min read
TypeScript is a programming language built by Microsoft as a superset of JavaScript: every valid JavaScript file is already valid TypeScript, and TypeScript adds an optional static type system on top. You write TypeScript, and a compiler (tsc) checks the types and then outputs plain JavaScript that runs anywhere JavaScript already runs — the browser, Node.js, wherever.
function greet(name: string): string {
return `Hello, ${name}!`;
}
greet("Ada"); // fine
greet(42); // compile error -- Argument of type 'number' is not assignable to parameter of type 'string'That : string after name is a type annotation — it tells TypeScript what type is expected, and TypeScript checks every call against it before the code ever runs.
Static typing vs JavaScript's dynamic typing
JavaScript checks types at runtime, if at all — passing the wrong type into a function often doesn't fail loudly, it just produces a wrong result or a confusing error somewhere downstream ("5" + 3 silently becomes "53" rather than throwing). TypeScript's type checker runs before your code executes at all, during development or as part of a build step, catching an entire category of bugs — wrong argument types, typo'd property names, calling a method that doesn't exist on a given type — at the point you write them instead of when a user hits them in production.
TypeScript compiles away
At runtime, none of TypeScript's types exist — tsc strips them out entirely, leaving plain JavaScript:
// input.ts
function double(n: number): number {
return n * 2;
}// output.js
function double(n) {
return n * 2;
}This matters conceptually: TypeScript's type system is purely a development-time tool. It can't catch something that depends on a value only known at runtime (like the actual content of an API response, unless you tell it what shape to expect), and there's zero runtime performance cost from using it — the types add nothing to the JavaScript that actually ships.
Why teams adopt it
Large JavaScript codebases tend to accumulate exactly the kind of bugs static types catch — a function that used to take a string now expects an object, and three call sites elsewhere in the codebase never got updated. TypeScript's compiler finds every one of those immediately, and editors like VS Code use the same type information to power autocomplete, inline documentation, and "find all usages" — tooling that's much weaker on plain JavaScript, where the editor has to guess at a value's shape.
The next lesson looks directly at what TypeScript actually adds on top of JavaScript, and what adopting it costs in practice.