The TypeScript repository at https://github.com/microsoft/TypeScript contains the complete implementation of the TypeScript language compiler, language service, and related development tooling infrastructure. This document provides a high-level overview of the repository's architecture, major systems, and how they interconnect.
For detailed information about specific subsystems:
This repository implements:
tsc): Compiles TypeScript source code to JavaScript with type checking and emittsserver): Long-running server process that exposes language service features to editors via JSON-RPC protocolSources: package.json1-62
Sources: package.json22-27 package.json42-62
Sources: src/compiler/scanner.ts1-50 src/compiler/parser.ts1-50 src/compiler/binder.ts1-50 src/compiler/checker.ts1-50 src/compiler/emitter.ts1-50 src/compiler/program.ts1-50 src/services/services.ts1-50 src/server/session.ts1-50
This diagram shows how TypeScript source code flows through the compilation pipeline with specific code entities:
Sources: src/compiler/scanner.ts1-100 src/compiler/parser.ts400-500 src/compiler/binder.ts1-100 src/compiler/checker.ts1-100 src/compiler/emitter.ts1-100 src/compiler/types.ts1-100
| Directory | Purpose | Key Components |
|---|---|---|
src/compiler/ | Core compiler implementation | scanner.ts, parser.ts, binder.ts, checker.ts, emitter.ts, program.ts |
src/services/ | Language service features | services.ts, completions.ts, findAllReferences.ts, refactors/, codefixes/ |
src/server/ | TSServer editor protocol | session.ts, project.ts, editorServices.ts, protocol.ts |
src/lib/ | Standard library definitions | es5.d.ts, dom.generated.d.ts, lib.*.d.ts |
src/compiler/transformers/ | AST transformations | ts.ts, es2015.ts, module.ts, jsx.ts |
tests/ | Test infrastructure | baselines/, cases/, compiler/, fourslash/ |
built/local/ | Build output directory | Compiled JavaScript and declaration files |
lib/ | Last Known Good (LKG) | Stable compiler used for bootstrapping |
Sources: src/compiler/types.ts1-50 src/services/services.ts1-50 src/server/session.ts1-50
The TypeScript compiler is built on a comprehensive type system defined in types.ts:
Sources: src/compiler/types.ts40-492 src/compiler/types.ts1000-2000
The Program interface orchestrates the entire compilation process:
Sources: src/compiler/program.ts1-100 src/compiler/program.ts1000-1100 src/compiler/commandLineParser.ts1-50
The Language Service provides IDE features on top of the compiler:
Sources: src/services/services.ts1-100 src/services/services.ts800-900 src/services/completions.ts1-50 src/services/findAllReferences.ts1-50 src/services/types.ts1-50
TSServer bridges editors to the Language Service via a JSON-RPC protocol:
Sources: src/server/session.ts1-100 src/server/editorServices.ts1-100 src/server/project.ts1-100 src/server/protocol.ts1-50
The compiler relies on several fundamental data structures:
| Type | Location | Purpose | Key Fields |
|---|---|---|---|
Node | types.ts:~800 | Base AST node | kind: SyntaxKind, pos, end, parent, flags |
SourceFile | types.ts:~3000 | Parsed source file | statements, fileName, text, languageVersion |
Symbol | types.ts:~5000 | Declaration symbol | flags: SymbolFlags, name, declarations, exports |
Type | types.ts:~6000 | Type representation | flags: TypeFlags, symbol, aliasSymbol |
Signature | types.ts:~6500 | Function/method signature | parameters, returnType, typeParameters |
Diagnostic | types.ts:~7500 | Error/warning message | category, code, messageText, file, start |
Program | types.ts:~3500 | Compilation context | getRootFileNames(), getSourceFile(), emit() |
LanguageService | services/types.ts:~200 | IDE features | getCompletions(), getDefinition(), findReferences() |
Sources: src/compiler/types.ts800-850 src/compiler/types.ts3000-3100 src/compiler/types.ts5000-5100 src/compiler/types.ts6000-6100 src/services/types.ts200-300
The main TypeScript module exports a comprehensive API surface:
Sources: tests/baselines/reference/api/typescript.d.ts1-100 src/compiler/types.ts1-50 src/services/types.ts1-50
TypeScript bootstraps itself using the Last Known Good (LKG) compiler:
Sources: Herebyfile.mjs scripts/build/build.mjs package.json1-62
TypeScript includes comprehensive type definitions for JavaScript and Web APIs:
| Library File | Purpose | Lines | Source |
|---|---|---|---|
lib.es5.d.ts | ES5 standard library | ~4500 | Hand-written |
lib.es2015.d.ts | ES2015+ features | ~1000 | Hand-written |
lib.dom.d.ts | DOM and Web APIs | ~27000 | Auto-generated from Web IDL |
lib.webworker.d.ts | Web Worker APIs | ~3000 | Auto-generated |
lib.scripthost.d.ts | Windows Script Host | ~200 | Hand-written |
lib.decorators.d.ts | Decorators | ~50 | Hand-written |
Sources: src/lib/ src/compiler/diagnosticMessages.json1-50
The repository uses hereby for task orchestration:
Sources: Herebyfile.mjs tests/cases/fourslash/fourslash.ts1-20 package.json41-62
This overview provides a foundation for understanding the TypeScript compiler codebase. For detailed information about specific subsystems, refer to the linked documentation pages for each major component.
Refresh this wiki