Inside the compiler
Scanner, parser, binder, checker, emitter; why esbuild and swc only strip types; isolatedModules. A free TypeScript lesson with examples.
More on The compiler
Keep learning
Overview
chapters · the compiler Inside the compiler tsc does two separate jobs: check types and write JavaScript. Most tools only do the second. tsc is the TypeScript compiler. Writing the output .js files is called emit.
1. The problem: red errors, and the JavaScript still ships
The left file has two type errors. The right file is what tsc wrote anyway. checkout.ts: two type errors Type 'string' is not assignable to type 'number'. 'Order' only refers to a type, but is being used as a value here. Line 2: "5" in quotes is text, so it does not fit a number. Line 5: instanceof needs a real class that exists while the program runs. An interface exists only for checking and is deleted from the output. checkout.js: tsc wrote it anyway Runtime: ReferenceError: Order is not defined. Use noEmitOnError to block output. Type errors do not stop emit (writing the .js). Types never reach the output, so they cannot run either. Line 1 is blank because the interface was erased.
2. Five stages, one line of code
text → tokens tokens → AST (syntax tree) names → symbols, scopes types, errors AST → .js, .d.ts, .map The checker is the big, slow part. The emitter does not depend on its verdict. source text scanner: tokens parser: AST binder: symbols symbol "tip" → block-scoped variable in this module checker: types declared number, got "5" → error TS2322 (“not assignable”) emitter: JS Syntax errors Found by the parser. A missing ) stops everything. Duplicate names Type errors Found by the checker. Emit still happens.
3. What the emitter keeps and what it erases
JavaScript output (5 as number) satisfies number Real runtime code. constructor(private name: string) Parameter property: real code. Verified with tsc 5.6, target es2022. Green rows simply vanish. Yellow rows generate code. Glossary for the table: as means “trust me, treat it as this type”. satisfies means “check it fits, keep its exact type”. A trailing ! means “trust me, this is not null”. All three only talk to the checker, so they leave no trace. enum, namespace and private name in a constructor create real objects or assignments, so code remains. a compile error
4. tsc versus the transpile-only tools
To transpile is to translate TypeScript into JavaScript. esbuild, swc, Babel and Node do only that: they strip the types. They look at one file at a time and never run a checker. checks types writes .js writes .d.ts enum / namespace esbuild (Vite) very fast swc (Next.js) Babel preset-typescript Node --experimental-strip-types Node's strip-only mode rejects enum: “TypeScript enum is not supported in strip-only mode” (tested on Node 22). The fast loop Bundler strips types per file and serves JS in milliseconds. Errors only show in the editor. The safety net tsc --noEmit (check only, write nothing) runs in CI, the automatic checks on every push. It is the only step that actually checks types.
5. Why isolatedModules and verbatimModuleSyntax exist
Look at what esbuild sees tsc --noEmit npm run typecheck && vite build
Remember
Pipeline: scanner → parser → binder → checker → emitter. esbuild, swc, Babel and Node strip types file by file and never check. verbatimModuleSyntax + import type make one-file tools safe. Apps: noEmit + bundler. Libraries: emit .d.ts. ! Cheat code Types never run. Your bundler never type-checks, so run tsc --noEmit in CI. Turn on verbatimModuleSyntax and write import type. → Go deeper: tsconfig that catches bugs, TS-only features, declaration files, slow types.
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
- Databases in depth — How a query becomes work. Indexes, isolation, locks, and the plans that explain why a page is slow — not an ORM tour.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.