TypeScript#

TypeScript is JavaScript with a static type layer. The operator’s source compiles to JavaScript (or runs directly under tsx, ts-node, Deno, or Bun) and the type checker catches the class of bugs that the dynamic runtime would let through.

For the operator, TypeScript is the default for any JavaScript-shaped project bigger than a single script. It is the language of choice for IDEs (VS Code, Cursor), most Anthropic / OpenAI SDKs, and the modern serverless and frontend stacks (Next, Remix, Svelte, Astro, Hono).

Baseline. TypeScript 5.4+ is assumed. Recipes target ESM, strict: true, noUncheckedIndexedAccess: true, and the modern type-flow features (satisfies, const type parameters, template literal types).

Default toolchain. tsc for type checking, tsx / vite / esbuild for running and bundling, eslint plus @typescript-eslint for lint, vitest for tests. The package manager is the same as JavaScript: npm / pnpm / yarn.

This section focuses on what TypeScript adds to JavaScript. The shared surface (loops, classes, modules, promises, the event loop) lives in JavaScript; TypeScript inherits all of it.

Setup#

Picking the toolchain and bootstrapping a project.

Setup

tsc --init, tsconfig.json, strict, module, target. Bootstrapping a project.

Setup
Tooling

tsc, tsx, esbuild, vite, tsup, @typescript-eslint, prettier, vitest. The modern toolchain.

Tooling
Snippets

Type guards, never exhaustiveness, satisfies, zod schemas.

Snippets

Language#

The spec building blocks: where TypeScript layers types on top of the JavaScript surface.

Syntax

:, as, !, ?, readonly, declare. Type annotations, assertions, non-null, optional members.

Syntax
Variables

const, let, var, as const, declaration narrowing, control-flow analysis.

Variables
Types

string number boolean object unknown never any, union, intersection, literal, template literal, mapped, conditional, infer.

Types
Operators

typeof, keyof, in, instanceof, satisfies, as. Type-level operators and narrowing.

Operators
Controls

if, switch, exhaustive never checks, discriminated unions, type guards in conditions.

Control flow
Functions

Signatures, overloads, generics, this parameter, type guards, asserts, function-type aliases.

Functions
OOP

class, interface, abstract, implements, access modifiers, parameter properties, generics on classes.

OOP

Patterns#

The layer above the spec.

Patterns

Discriminated unions, branded types, Result types, builder pattern, satisfies, declaration merging.

Patterns
Errors

try catch finally, typed errors, Error subclasses, Result<T, E> structures, never for exhaustive catch.

Errors

Data Structures#

Typed containers.

Structures

Array<T>, tuples, ReadonlyArray<T>, Map<K,V>, Set<T>, Record<K,V>, typed arrays.

Data Structures
Algorithms

Type-safe sort, map, filter, reduce, with generic helpers and inference.

Algorithms

I/O#

Same I/O surface as JavaScript; the type layer makes the data structures explicit.

I/O

fs/promises, readFile, typed JSON.parse with zod, Buffer, typed streams.

I/O
CLI

process.argv, commander, citty, yargs, typed option parsing, typed exit codes.

CLI
Networking

fetch, undici, ws, typed responses with zod, OpenAPI client generation.

Networking
Concurrency

Typed Promise<T>, async / await, worker_threads with shared types, AbortSignal.

Concurrency

Runtime#

Where the type checker stops and JavaScript starts.

Runtime

tsc, tsconfig.json, source maps, .d.ts declaration files, module / moduleResolution, isolatedModules, the type-erasure model.

Runtime

Ecosystem#

The third-party catalog.

Libraries

Core: zod, valibot, ts-pattern, type-fest, effect. CLI: commander, citty, chalk.

Libraries
Frameworks

Web: hono, express, fastify. Full-stack: next, remix. UI: react, svelte, solid. Build: vite, tsup.

Frameworks

Practice#

The disciplines that make typed code safe to ship.

Testing

vitest, jest, tsd for type-only tests, expect-type, playwright.

Testing
Projects

End-to-end TypeScript projects: an OSINT API, a Hono service, a typed MCP server.

Projects