Course contentsShow
← TypeScript
Lesson 1540 of 1,79635. TypeScript with Framework Cross-ReferencesFree lesson

Framework Comparison: Where Types Come From

Comparing Express manual typing, Hono's path-based inference, and Fastify's schema-driven approach.

Framework Comparison: Where Types Come From

You'll learn how Express, Hono, and Fastify take fundamentally different approaches to generating TypeScript types for your routes and handlers.

The Three Type-Generation Philosophies

Each framework represents a different era and philosophy of TypeScript integration:

Express: Manual Typing — You define everything yourself through generics. Express doesn't know your route paths at compile time.

Hono: Path-Based Inference — The framework uses literal string types from your route definitions to infer parameter types automatically.

Fastify: Schema-Driven Approach — You define JSON schemas, and TypeScript types are derived from those schemas (or vice versa with type providers).

Where Your Types Live

Express: You Bring the Types

In Express, types come from you. You pass generic type arguments to Request to tell TypeScript what shapes to expect:

  • Request body? You define the interface.
  • Route params? You specify them as generics.
  • Query strings? More interfaces you maintain separately.

Express has no connection between the route string '/users/:id' and the types you use. It's all manual bookkeeping.

Hono: Types Come From Your Routes

In Hono, types emerge from the route path itself. When you write app.get('/users/:id'), Hono's type system parses that literal string and infers that c.req.param('id') must exist and return a string.

The source of truth is the route definition. The framework does template literal type parsing to extract parameters.

Fastify: Types Come From Schemas

In Fastify, types originate from JSON Schema or type providers. You either define a schema that gets converted to TypeScript types, or use type providers to generate schemas from TypeScript types.

The framework prioritizes runtime validation and type safety together — your schema validates at runtime AND provides compile-time types.

The Trade-Off Triangle

Each approach trades flexibility, safety, and convenience differently:

  • Express: Maximum flexibility, minimum built-in safety, manual effort required
  • Hono: High inference, excellent DX for simple cases, opinionated structure
  • Fastify: Schema-first thinking, validation + types together, some boilerplate

Key Takeaway: Express makes you do all the type work manually, Hono infers types from your route paths using TypeScript's literal type system, and Fastify generates types from schemas that also provide runtime validation — choose based on whether you value flexibility, inference magic, or validation-driven development.