Skip to content

How to use TypeScript types to understand a codebase

Types are documentation the compiler checks. How to read domain types, function signatures, unions, generics and utility types to understand unfamiliar TypeScript.

October 13, 2026 · 2 min read · RepoGrasp team

In a TypeScript codebase, types are the most reliable documentation you have: the compiler checks them on every build, so unlike comments they can't silently drift. Reading types first often explains a codebase faster than reading implementations.

Start with the domain types

Look for files or folders called types, models, domain or schema, or types generated from a database or API (Prisma's generated types, GraphQL codegen output, OpenAPI clients). These describe the nouns of the system: users, orders, invoices and their fields.

Read them like a data dictionary. Which fields are optional? Which are unions? What references what?

Read signatures before bodies

A function's signature tells you its contract:

function applyDiscount(order: Order, code: string): Result<Order, DiscountError>

Before reading the body, you know it takes an order and a code, returns either an updated order or a specific error, and doesn't throw for expected failures. Hover in your editor to see inferred return types too.

Unions describe states

type Payment =
  | { status: "pending" }
  | { status: "succeeded"; chargeId: string }
  | { status: "failed"; reason: string };

A discriminated union like this lists every state something can be in and what data exists in each state. Code that switches on status handles each one. Unions are some of the most informative types in a codebase.

Generics show what's reusable

Repository<T>, useQuery<TData> or ApiResponse<T> mark general-purpose building blocks. Find where they're instantiated to see what they're used for.

Utility types show relationships

  • Pick<User, "id" | "email"> is a subset of a type.
  • Omit<Order, "id"> is often a "create" input.
  • Partial<Settings> is usually an update payload.
  • ReturnType<typeof fn> ties a type to a function's output.

These tell you how types relate, such as which shape is sent to the API versus stored.

Types from schemas

Many codebases derive types from runtime schemas: z.infer<typeof OrderSchema> with Zod, or Valibot and TypeBox equivalents. The schema is then the source of truth for both validation and types. Read the schema.

Where types can mislead

  • any and type assertions (as Order) switch checking off. Search for them in critical paths.
  • Types describe what code expects, not what external data actually contains. Data from APIs, files or the database is only safe if it's validated.
  • Declaration files (.d.ts) for untyped libraries can be wrong.

Ask about types and their use

Ask RepoGrasp "what states can a Payment be in, and where does each transition happen?" It reads type definitions and the code that uses them, and cites both. Types make cited answers more precise, because the structure is explicit.

Try it.