TypeScript
JavaScript with a type system. The language most production codebases use, even ones that look like JavaScript.
Mindmap
The plain-English version
TypeScript is a language that compiles down to JavaScript and adds a static type system. You write function add(a: number, b: number): number instead of function add(a, b). The compiler catches type errors before they ship. The output is plain JS that runs anywhere JS does.
The problem it solves
JavaScript's loose typing is a gift in small scripts and a liability in big codebases. TypeScript catches a class of bugs before runtime, makes refactoring safer, and gives editors real autocomplete. By 2024 it's the default in most production codebases — and most modern AI agents use it by default unless told otherwise.
Alternatives
| Alternative | Type | When it wins |
|---|---|---|
| Node.js | runtime | JavaScript outside the browser. The runtime that powers most modern web backends, build tooling, and AI agent CLIs. |
| Python | language | The default language of data, ML, and quick scripts. Increasingly the second language even in JS-first stacks. |
Deep links
The words you'll hear
- Type
- A description of what shape a value has.
string,number,{name: string}. - Interface
- A named type for an object shape.
interface Task { id: string; title: string }. - Generic
- A type parameter.
function first<T>(arr: T[]): T— a function whose type depends on its input. - Union / intersection
string | number(either) andA & B(both).- Type guard
- A check at runtime that narrows a type.
if (typeof x === "string") {...}. strict- Compiler flag. Turns on null checks, no-implicit-any, etc. Always start strict.
Bad vs. good prompt for TypeScript
Why it works: Specifies strict, says where shared types live, names the union, asks for documentation. Prevents the agent from peppering the file with any.
What bites real teams
anyany opts out of the type system. Use unknown instead — it forces you to narrow before using the value.
TypeScript types vanish at runtime. typeof, instanceof, schema libraries (Zod, Valibot) bring type-safety to data crossing the boundary.
Don't write a generic when a simple type works. Don't write conditional types when a union works. Read the existing code's style.