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.
tsc --init, tsconfig.json, strict, module,
target. Bootstrapping a project.
tsc, tsx, esbuild, vite, tsup,
@typescript-eslint, prettier, vitest. The
modern toolchain.
Type guards, never exhaustiveness, satisfies,
zod schemas.
Language#
The spec building blocks: where TypeScript layers types on top of the JavaScript surface.
:, as, !, ?, readonly, declare.
Type annotations, assertions, non-null, optional members.
const, let, var, as const, declaration
narrowing, control-flow analysis.
string number boolean object unknown never any,
union, intersection, literal, template literal,
mapped, conditional, infer.
typeof, keyof, in, instanceof,
satisfies, as. Type-level operators and narrowing.
if, switch, exhaustive never checks,
discriminated unions, type guards in conditions.
Signatures, overloads, generics, this parameter,
type guards, asserts, function-type aliases.
class, interface, abstract, implements,
access modifiers, parameter properties, generics on
classes.
Patterns#
The layer above the spec.
Discriminated unions, branded types, Result types,
builder pattern, satisfies, declaration merging.
try catch finally, typed errors, Error subclasses,
Result<T, E> structures, never for exhaustive catch.
Data Structures#
Typed containers.
Array<T>, tuples, ReadonlyArray<T>, Map<K,V>,
Set<T>, Record<K,V>, typed arrays.
Type-safe sort, map, filter, reduce,
with generic helpers and inference.
I/O#
Same I/O surface as JavaScript; the type layer makes the data structures explicit.
fs/promises, readFile, typed JSON.parse with
zod, Buffer, typed streams.
process.argv, commander, citty, yargs,
typed option parsing, typed exit codes.
fetch, undici, ws, typed responses with
zod, OpenAPI client generation.
Typed Promise<T>, async / await,
worker_threads with shared types, AbortSignal.
Runtime#
Where the type checker stops and JavaScript starts.
tsc, tsconfig.json, source maps, .d.ts
declaration files, module / moduleResolution,
isolatedModules, the type-erasure model.
Ecosystem#
The third-party catalog.
Core: zod, valibot, ts-pattern,
type-fest, effect. CLI: commander,
citty, chalk.
Web: hono, express, fastify. Full-stack:
next, remix. UI: react, svelte,
solid. Build: vite, tsup.
Practice#
The disciplines that make typed code safe to ship.
vitest, jest, tsd for type-only tests,
expect-type, playwright.
End-to-end TypeScript projects: an OSINT API, a Hono service, a typed MCP server.