image.png

A Glimpse into the TypeScript Codebase

Before diving into the pipeline, it's helpful to understand the TypeScript project itself:

Self-Hosted: TypeScript is famously built using TypeScript, making it a self-hosted language.

Scale: The core compiler code, shipped as an npm module, is roughly a quarter of a million lines. Including tests and other files, the total codebase is significantly larger.

Testing: It boasts around 80,000 separate test files, primarily using a "before and after" integration testing style.

Core Files: While the main export comprises about 5,000 files, the bulk of the work is concentrated in about eight "mega files."

Activity: Following the repository means a lot of updates—around 70 notifications per day!

History: TypeScript is 11 years old and has undergone 2.5 major rewrites. It began in F# alongside a C# version, then became self-hosted in TypeScript, and later transitioned from a class-based style to a more functional approach in version 1.1.

image.png

The Compiler's Orchestrator: The Program Object

image.png

Your primary interaction with the TypeScript compiler API is through an object called "the Program." Think of it as the project coordinator for the entire compilation process. Despite its significant role, it's a relatively modest 4,000 lines of code.

When you run tsc from the command line, it's largely "the Program" setting up and managing the compilation. The typical workflow involves three major steps:

  1. Creation: You first create a "Program" instance, providing it with your source files.
  2. Type Checking (Optional): You can then instruct the type checker to analyze your files. This step is optional if your goal is solely to transform TypeScript to JavaScript without type validation.
  3. Emission: Finally, the "emit" phase takes the in-memory representations and converts them back into output files (JavaScript, source maps, etc.).

For more in-depth documentation on "the Program" and the compiler API, refer to the TypeScript wiki.

The Compilation Journey: Three Key Stages

The talk frames the compilation process around these three distinct areas: