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:
SourceFile, Symbol, and Type, see Key Concepts and ArtifactsThis repository implements the following core components:
tsc): The command-line implementation that performs scanning, parsing, type checking, and code generation.tsserver): A standalone server process that encapsulates the language service and communicates with editors via a JSON-RPC protocol..d.ts files that define the environment (e.g., lib.es5.d.ts, lib.dom.d.ts).Sources: package.json1-62 package-lock.json1-62
Sources: package.json11-14 src/compiler/program.ts42-50 src/services/services.ts212-214 src/compiler/utilities.ts138
The compiler is organized into several distinct layers, moving from raw source text to semantic understanding and finally to generated output.
Sources: src/compiler/scanner.ts1-30 src/compiler/parser.ts1-30 src/compiler/binder.ts1-30 src/compiler/checker.ts1-30 src/compiler/emitter.ts1-30 src/compiler/program.ts1-30 src/services/services.ts1-30 src/server/session.ts1-30
This diagram bridges the natural language phases to specific code entities and functions within the codebase.
Sources: src/compiler/types.ts40-227 src/compiler/parser.ts220-221 src/compiler/binder.ts47 src/compiler/checker.ts132 src/compiler/emitter.ts66-76
| 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 |
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 |
tests/ | Test infrastructure | baselines/, cases/, fourslash/ |
lib/ | Last Known Good (LKG) | Stable compiler used for bootstrapping |
Sources: src/compiler/types.ts1-50 src/services/services.ts1-50 src/server/editorServices.ts1-50
The compiler relies on several fundamental data structures defined primarily in types.ts.
| Type | Location | Purpose |
|---|---|---|
Node | src/compiler/types.ts | Base interface for all AST nodes. |
SourceFile | src/compiler/types.ts | Represents a parsed source file with its AST and metadata. |
Symbol | src/compiler/types.ts | Represents a named entity (variable, function, class) across declarations. |
Type | src/compiler/types.ts | The internal representation of a type in the type system. |
Diagnostic | src/compiler/types.ts | Represents a compiler error, warning, or suggestion. |
Program | src/compiler/types.ts | The primary object coordinating compilation of a set of files. |
Sources: src/compiler/types.ts228-300 src/compiler/types.ts1-50 src/compiler/checker.ts148-156
TypeScript bootstraps itself using the Last Known Good (LKG) compiler. The build system is orchestrated by hereby.
Sources: Herebyfile.mjs1-50 package.json43 package-lock.json37
For detailed information about the monorepo structure and entrypoints, see Repository Tour and Package Layout. For definitions of the core compiler artifacts, see Key Concepts and Artifacts.