Skip to content

Lesson 45 of 50TypeScript

The TypeScript Toolchain in 2026

Type checking vs type stripping, erasable syntax, what changed in TypeScript 6 and 7, project references, and how to find out why a type check is slow.

15 min read0/4 questions

On your first week at a new job you will probably meet three TypeScript problems that have nothing to do with writing types. The CI type check takes eight minutes. Someone ran a .ts script straight with node and it crashed on an enum. And a dependency upgrade bumped TypeScript to 7.0, and now half the team's tsconfig.json options are errors. This lesson is the toolchain layer under the language: which tool does what, what changed in 2026, and how to make a large project fast to check. It builds on Modules and tsconfig, so the basic options are not repeated here.

Two jobs, and nobody does both any more

As you saw in Modules and tsconfig, a modern project splits TypeScript into two jobs.

  • Type checking: read the whole program, build every type, report errors. Only tsc (or the editor's language server, which is the same engine) does this.
  • Emitting JavaScript: turn each .ts file into .js. Almost everything can do this: esbuild, SWC, Oxc, Babel, Bun, Deno and now Node itself.

The emitters are fast because they never look at other files. They delete the type syntax in one file and move on. That one design choice explains most of the rules in this lesson. If a feature needs knowledge from another file, or needs to generate new runtime code, a per-file stripper either cannot handle it or has to guess.

ToolJobWhere you meet it
tsc --noEmitCheck onlyCI, npm run typecheck, the editor
tsc / tsc -bCheck and emit .js + .d.tsLibraries, project references
Vite (esbuild / Oxc)Strip types per fileFrontend dev server and build
Next.js (SWC)Strip types per filenext dev, next build
Node 22.18+ / 23.6+Strip types at load timeScripts, small services
tsxStrip types (esbuild) and runScripts that use path aliases or enums

Next.js is the one common exception that also type-checks during next build. Vite does not: a Vite app with type errors builds and ships happily unless CI runs tsc.

Type stripping and erasable syntax

Node can now run TypeScript files directly. Since Node 22.18 and 23.6, node server.ts works with no flag. Node does not compile anything. It replaces type syntax with whitespace, so line and column numbers in stack traces still match your source and no source map is needed.

That only works for syntax that is erasable: delete it and valid JavaScript with the same behaviour is left. Most TypeScript is erasable. A few features are not, because they generate runtime code.

erasable.ts
// Erasable: delete the types and the program behaves the same
interface User { id: string; name: string }
type Role = "admin" | "member";
function greet(u: User, role: Role): string { return `${u.name} (${role})`; }
const n = JSON.parse("1") as number;
const routes = { home: "/" } satisfies Record<string, string>;
not-erasable.ts
// Not erasable: each of these creates JavaScript that is not in the source
enum Status { Active, Banned }               // becomes an object with reverse mappings
namespace Billing { export const rate = 2; } // becomes an IIFE
class Repo { constructor(private db: Db) {} } // parameter property assigns this.db
import fs = require("node:fs");              // CommonJS import syntax
type Db = { query(sql: string): unknown };

The compiler option erasableSyntaxOnly (TypeScript 5.8) turns all of these into errors, so your code stays runnable by any stripper. If you plan to run .ts files with Node, or want to keep your options open, switch it on. The replacements are short:

TypeScript
// Instead of: enum Status { Active = "active", Banned = "banned" }const Status = { Active: "active", Banned: "banned" } as const;type Status = (typeof Status)[keyof typeof Status]; // "active" | "banned" function label(s: Status): string { return s === Status.Banned ? "Account banned" : "OK";} // Instead of a parameter property: declare the field and assign itclass Repo { private readonly db: string[]; constructor(db: string[]) { this.db = db; } count(): number { return this.db.length; }} console.log(label(Status.Banned), Object.keys(Status).length, new Repo(["a", "b"]).count());
Output
Press Run (⌘ Enter) to see what happens.

The as const object gives you the same autocomplete as an enum, plus a plain string union that serialises cleanly to JSON. A number enum also has a surprise: Object.keys on it returns twice as many keys as you wrote, because of the reverse mappings.

Imports: verbatimModuleSyntax and extensions

A stripper sees import { User } from "./types" and cannot know whether User is a type (delete the import) or a value (keep it). verbatimModuleSyntax settles it: anything imported without the type keyword stays in the output exactly as written. So you write import type { User } or import { type User, saveUser }, and the stripper never guesses. It replaces the older importsNotUsedAsValues and preserveValueImports options, and it turns on isolatedModules for you, which bans the other patterns a single-file tool cannot handle, such as re-exporting a type without export type.

Node adds two more rules. It does not read tsconfig.json, so paths aliases do not work (use package.json imports with # names instead). And it needs real file extensions: import { db } from "./db.ts". Turn on allowImportingTsExtensions with noEmit for that, or rewriteRelativeImportExtensions if tsc also emits .js files for publishing.

Quick check
With erasableSyntaxOnly on, which line is an error?
Need a nudge? A hint rules out a wrong answer.

TypeScript 6.0 and 7.0

2026 was the biggest year for the compiler since it launched.

The compiler in 2026
  1. Mar 2026

    TypeScript 6.0

    The last release of the JavaScript-based compiler. New defaults, and a long list of deprecations to clear the way for 7.0.

  2. Jul 2026

    TypeScript 7.0

    The native compiler, a port of the same checker to Go. Installed as the normal typescript package. Typical builds run around 8 to 12 times faster.

  3. Oct 2026

    TypeScript 7.1 beta

    Brings the programmatic API back, which tools such as linters and framework plugins need.

What 6.0 changed

TypeScript 6.0 changed defaults that had stood for a decade. With no tsconfig.json options set, you now get:

  • strict: true.
  • module: esnext and a target of the latest ECMAScript year (es2025).
  • types: []. Global @types packages are no longer included automatically. If code uses process or describe as globals, list them: "types": ["node", "vitest/globals"].
  • rootDir set to the folder that holds the tsconfig.
  • noUncheckedSideEffectImports: true, so import "./polyfil" with a typo is an error instead of silently doing nothing.

It also deprecated options that 7.0 then removed: target: es5, downlevelIteration, moduleResolution: node (also called node10) and classic, baseUrl as a lookup root, the amd, umd, systemjs and none module formats, outFile, esModuleInterop: false, asserts on imports (use with), and the module Foo {} spelling of namespaces. If a blog post tells you to set moduleResolution: "node", it is out of date: use bundler for bundled apps and nodenext for code Node runs.

The most common upgrade error looks like a missing type, not a config problem:

src/server.ts(3,20): error TS2591: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.

You already have @types/node installed. The fix is "types": ["node"], because the new default no longer pulls it in.

What 7.0 changed

TypeScript 7.0 is the same type system with a new engine. The checker was ported to Go, runs natively, and type-checks files in parallel. You install it as typescript and run tsc as before. Two new flags control the parallelism: --checkers sets how many checker workers each project uses, and --builders sets how many projects tsc -b builds at once. --singleThreaded turns it all off, which helps when you debug a crash or compare output.

The catch is the ecosystem. Version 7.0 shipped without the stable JavaScript API that the old typescript package exposed, so tools that call the compiler as a library could not move yet. Type-aware lint rules, some codegen tools and editor plugins for Vue, Svelte, Astro and MDX were in that group. The workaround is to run both: typescript 7 for tsc and the editor, and the 6.x compiler installed under the alias package @typescript/typescript6 for tools that need the old API. Check each tool's docs for its TypeScript 7 status before you upgrade a work project.

Put it in order5 steps

Put the steps of a safe upgrade from TypeScript 5.x to 7.0 in order.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.

Project references and tsc -b

In a monorepo or a big app, checking everything as one program wastes time. Change one line in ui/ and tsc re-checks the API code too. Project references split the code into smaller TypeScript projects that build in dependency order and cache their results.

packages/ui/tsconfig.json
{
  "compilerOptions": {
    "composite": true,
    "declaration": true,
    "declarationMap": true,
    "outDir": "dist"
  },
  "include": ["src"],
  "references": [{ "path": "../shared" }]
}
tsconfig.json (repo root)
{
  "files": [],
  "references": [
    { "path": "packages/shared" },
    { "path": "packages/ui" },
    { "path": "apps/web" }
  ]
}

composite tells TypeScript the project can be referenced. It forces declaration on and requires every source file to match include, so the project's boundary is explicit. When ui imports from shared, the checker reads shared's emitted .d.ts files instead of its source, which is much cheaper. declarationMap keeps go-to-definition jumping to the real source instead of the .d.ts.

tsc -b after editing one file in shared
shared: compositesharedcompositeui: refs shareduirefs sharedapi: refs sharedapirefs sharedapps/web: refs ui, sharedapps/webrefs ui, sharedd.tsd.tsd.ts

tsc -b reads each project's .tsbuildinfo file. Only shared has a changed source file, so it is rebuilt first.

1/3

Use tsc -b (build mode) at the root, not tsc -p. Build mode walks the references, skips projects that are up to date, and stores state in .tsbuildinfo files. In CI, cache those files between runs and the second run of an unchanged project costs almost nothing. The common mistakes: forgetting a references entry (you get confusing "file is not listed within the file list" errors), and importing another package's source by a relative path like ../../shared/src, which bypasses the boundary.

Diagnosing a slow type check

When tsc or the editor gets slow, measure before you guess.

npx tsc --noEmit --extendedDiagnostics

The output lists files, lines, types, instantiations, memory used, and time per phase. Look at three numbers. If Files is far higher than expected, include is picking up dist or generated code. If Check time dominates and Instantiations is in the millions, some type is doing too much work. If memory is near your machine's limit, split the project with references.

To find which type, record a trace:

npx tsc --noEmit --generateTrace tracenpx @typescript/analyze-trace trace

The analyser lists hot spots by file and position. You can also load trace/trace.json into a performance viewer such as Perfetto. The tracing tools were built for the JavaScript compiler, so check their docs for TypeScript 7 support, and fall back to the 6.x compiler for a trace if needed.

The usual causes, in the order seniors check them:

  1. Huge unions. A template literal type over three unions of 30 members each is 27,000 members, and every comparison against it is expensive.
  2. Deep recursive types, such as a Paths<T> over a large generated schema.
  3. Inferred types of big objects. A 2,000-line tRPC router or a giant as const object has to be re-inferred whenever its dependencies change. An explicit annotation at the boundary stops that.
  4. Intersections of large object types instead of interface ... extends, because interfaces are cached by name and intersections are recomputed.
What 'Type instantiation is excessively deep and possibly infinite' means

Error TS2589 is a safety limit, not a bug in your code. Every time the checker substitutes a type argument into a generic, it creates an instantiation. If one chain of substitutions gets too deep, the checker stops rather than hang your editor. You usually hit it with recursive conditional types over long strings or deeply nested data. The fixes are to cap the recursion with a depth counter (a tuple that grows by one each level, and a check against its length), to make the recursion tail-recursive (the recursive call is the whole result of a branch, which the checker can evaluate in a loop up to a much higher limit), or to stop computing the type and write it out.

isolatedDeclarations for libraries

Emitting .d.ts files has always needed the full type checker, because an exported function without a return type annotation has to be inferred. That made declaration emit the slow part of every library build. isolatedDeclarations (TypeScript 5.5) requires an explicit type on everything a file exports, so a .d.ts file can be produced from one file alone, without the checker.

// Error with isolatedDeclarations: the return type must be written out
export function parsePrice(raw: string) {
  return Number.parseFloat(raw);
}
 
// OK: anyone can emit the declaration from this file alone
export function parsePriceOk(raw: string): number {
  return Number.parseFloat(raw);
}

The payoff is in monorepos and libraries: declaration files can be emitted in parallel, by fast tools as well as by tsc, and the .d.ts for one package no longer waits for the check of another. The cost is writing return types on exports, which many teams already require for readability. Turn it on for published packages and shared internal packages, and leave it off for app code where nothing is exported to other projects.

Match the pairs0/5 matched

Match each problem to the option or command that addresses it.

Choose an item, then its match on the other side.

A setup that holds up at work

Put it together and a typical 2026 app has a short, boring config, which is the goal.

tsconfig.json
{
  "compilerOptions": {
    "target": "es2023",
    "module": "esnext",
    "moduleResolution": "bundler",
    "types": ["node"],
    "noUncheckedIndexedAccess": true,
    "verbatimModuleSyntax": true,
    "erasableSyntaxOnly": true,
    "skipLibCheck": true,
    "noEmit": true,
    "incremental": true
  },
  "include": ["src", "scripts"]
}

strict is not listed because it is the default now. incremental writes a .tsbuildinfo file even with noEmit, so a second local tsc run only re-checks what changed. In CI, run tsc --noEmit (or tsc -b in a monorepo) as its own job, in parallel with tests and lint, and fail the pull request on any error. Pin the TypeScript version in package.json, because a minor release can add new errors and you want that to happen in a deliberate upgrade, not on a random Tuesday.

Predict the outputTypeScript

What does this print?

enum Level { Low, High }
const Size = { Small: "s", Large: "l" } as const;

console.log(Object.keys(Level).length, Object.keys(Size).length);
Need a nudge? Hints walk you through it.
Key terms
type stripping
Removing type syntax from a file without checking it, often by replacing it with whitespace. What Node, esbuild, SWC and Oxc do.
erasable syntax
TypeScript syntax that can be deleted without changing runtime behaviour. Enums, namespaces and parameter properties are not erasable.
verbatimModuleSyntax
Keeps every import without the type keyword exactly as written, so per-file tools never guess whether an import is a type.
project references
Splitting a codebase into TypeScript projects that reference each other and build in order with tsc -b.
composite
Marks a project as referenceable. Forces declaration output and an explicit file list.
.tsbuildinfo
The cache file tsc writes in incremental and build mode, so unchanged work is skipped next time.
isolatedDeclarations
Requires explicit types on exports so .d.ts files can be generated per file without the type checker.