This page defines the core technical artifacts and conceptual entities used throughout the TypeScript codebase. Understanding these artifacts is essential for navigating the compiler, language service, and server implementations.
The compiler operates on a set of fundamental data structures that represent the code, its semantic meaning, and the overall compilation context.
A SourceFile is the top-level representation of a single TypeScript or JavaScript file src/compiler/types.ts3843-3889 It contains the full source text and a tree of Node objects src/compiler/types.ts747-814
kind property of type SyntaxKind, which identifies the grammatical construct (e.g., IfStatement, Identifier) src/compiler/types.ts40-455pos (start including trivia) and end src/compiler/types.ts28-31These objects represent the semantic "meaning" of the code after the binder and type checker have processed the AST.
Symbol src/compiler/types.ts4460-4493NumberType, UnionType, InterfaceType) src/compiler/types.ts4549-4628The Program is the central coordinator of a compilation session src/compiler/types.ts4051-4156 It holds the set of SourceFiles, the CompilerOptions, and provides access to the TypeChecker src/compiler/program.ts50-51
The following diagram illustrates how raw code maps to internal compiler artifacts.
Code to Entity Mapping
Sources: src/compiler/types.ts747-814 src/compiler/types.ts3843-3889 src/compiler/types.ts4460-4493 src/compiler/types.ts4549-4628
Diagnostics are the errors, warnings, and suggestions produced by the compiler src/compiler/types.ts4214-4241
code (e.g., 1002 for "Unterminated string literal"), a category, and a messageText src/compiler/diagnosticMessages.json2-5DiagnosticWithLocation includes a file, start, and length to point exactly where the issue occurs src/compiler/types.ts4234-4241Baselines are reference files used for regression testing. They live in tests/baselines/reference/.
.js, .d.ts, and errors against known good versions tests/baselines/reference/APISample_compile.js1-5The lib/ directory contains the "Last Known Good" version of the compiler. Because the TypeScript compiler is written in TypeScript, it requires a pre-compiled version of itself to build the current source code (bootstrapping).
Program src/services/services.ts212-213LanguageService and communicates with editors via a JSON-RPC protocol src/server/protocol.ts49-126The compiler interacts with the environment through a System host and manages files via ScriptInfo.
System Architecture and Data Flow
Sources: src/server/editorServices.ts182-195 src/server/project.ts1-10 src/server/scriptInfo.ts1-10
| Artifact | Primary Interface/Class | Primary Location |
|---|---|---|
| AST Node | Node | src/compiler/types.ts747 |
| Source File | SourceFile | src/compiler/types.ts3843 |
| Semantic Identity | Symbol | src/compiler/types.ts4460 |
| Type System Entity | Type | src/compiler/types.ts4549 |
| Compilation Unit | Program | src/compiler/program.ts50 |
| Error Reporting | Diagnostic | src/compiler/types.ts4214 |
| Language Server | Session | src/server/session.ts1-10 |
| Editor Logic | LanguageService | src/services/services.ts212 |
Sources: src/compiler/types.ts1-200 src/compiler/program.ts1-50 src/services/services.ts1-250
Refresh this wiki