TypeScript 7.0 native preview is available. Release notes

TSts-docs

TypeScript internals, described plainly.

One reference for the compiler, the checker, and the language service. Real signatures, short examples, version notes. Written for people building tools, plugins, and codemods.

npm i -D typescript@7.0.2

inspect-types.tsstrict
import ts from "typescript";

const program = ts.createProgram(["src/index.ts"], {
  strict: true,
  target: ts.ScriptTarget.ES2022,
});

const checker = program.getTypeChecker();
const source = program.getSourceFile("src/index.ts")!;

ts.forEachChild(source, (node) => {
  if (ts.isFunctionDeclaration(node)) {
    const sig = checker.getSignatureFromDeclaration(node);
    console.log(checker.signatureToString(sig!));
  }
});
No errors · 0.8 ms

Reference

Six surfaces. Each page lists signatures, a short example, and what changed by version.

Compiler

createProgram(rootNames, options)

Build a program, walk source files, emit output.

Checker

getTypeChecker()

Resolve types, symbols, and signatures at any node.

Language service

createLanguageService(host)

Completions, quick info, rename, and refactors.

Server

tsserver protocol

The session protocol editors speak to TypeScript.

Transforms

factory.updateNode et al.

Visitors and factories for codemods and emit.

Utilities

isTypeAssignableTo, displayParts

Small predicates that answer real questions.

Globals — String · Array · Promise · View all →

Start here

  1. Install and check a file

    npx tsc --init --strict · npx tsc --noEmit

  2. Read one program end to end

    Source file, program, checker, emitter — in that order.

  3. Answer one type question in code

    Use the checker to print the signature of a function you wrote.

Types, hovered

type Result<T> = {
  ok: true; value: T;
} | {
  ok: false; error: Error;
};

async function fetchUser(
  id: string,
): Promise<Result<User>>

checker

function fetchUser(id: string): Promise<Result<User>>

Assignable to Result<unknown>. Try satisfies to check shape without widening.