Documentation
Everything you need to set up TypeOwl in your project.
Installation
Install TypeOwl in both your backend and frontend projects:
Quick Start
Get TypeOwl running in 3 steps:
1. Backend: Create config file
2. Backend: Initialize and mount
3. Frontend: Sync types using CLI
Project Structure
- typeowl.server.config.ts Server config
-
src/
- server.ts Main server file
-
types/
- User.ts Type definitions
- Blog.ts
- typeowl.config.ts Client config
-
.typeowl/ Generated types (commit for independent deploys!)
- index.d.ts ApiEndpoints + re-exports
- content.d.ts All extracted types
- .typeowl-cache/ Local cache (gitignore)
-
src/
-
api/
- client.ts Type-safe API client
-
api/
Server Configuration
The typeowl.server.config.ts file controls how types are extracted and served:
| Option | Type | Description |
|---|---|---|
version |
string | Version string for cache invalidation |
basePath |
string | Base URL path (default: /__typeowl) |
typeSources |
string | string[] | Source files for type extraction (TypeChecker scans these) |
routes |
string | string[] | Route files to scan for route.get().returns<T>() patterns |
onConflict |
'error' | 'rename' | How to handle duplicate type names (default: 'error') |
mode |
'dynamic' | 'static' | How types are served |
guard |
object | Security settings (API key, environment) |
Type Extraction
TypeOwl can extract types directly from your TypeScript files:
route.get() — Pure TypeScript
The recommended way to define API types. Works with Fastify, Express, Hono, Next.js, and Koa:
- Pure TypeScript — no schemas, just interfaces and types
- TypeChecker extraction — robust type resolution
- Multi-framework — works with Fastify, Express, Hono, Next.js, Koa
- Conflict resolution — handles duplicate types with onConflict config
Conflict Resolution
When multiple files define types with the same name, TypeOwl uses structural comparison:
- Same structure — Types are merged silently (no conflict)
- Different structure — Handled based on
onConflictconfig
Validation with Typia (Optional)
TypeOwl doesn't include validation. Use Typia for runtime validation — it uses the same types from your route definitions:
- Access types directly:
route.bodyType,route.paramsType,route.responseType - No runtime schema overhead — validators generated at compile time
- 10-1000x faster than Zod/Yup
Static Extraction Only (No Routes)
Don't need API endpoint mapping? You can use TypeOwl purely for type sharing — just extract types from your backend files and sync them to the frontend. No copy/paste needed.
- You just want to stop copy/pasting types between repos
- You don't need API endpoint mapping
- You want the simplest possible setup
Setup: Create a dedicated folder (e.g., src/types/) for your shared types:
Client Configuration
Configure where to fetch types from. You can point to local dev, staging, or production!
Syncing Types
Use the TypeOwl CLI to sync types from your backend:
Add CLI commands to your package.json:
typeowl sync— [CLIENT] One-time sync from remote backendtypeowl watch— [CLIENT] Continuously poll for type changestypeowl generate— [SERVER] Pre-generate static types
Deployment Strategies
TypeOwl gives you flexibility in how you manage types. Choose the strategy that fits your workflow:
Strategy 1: Commit Types (Recommended)
- Guaranteed compatibility — Types match the API when code was written
- CI/CD works offline — No backend access needed during builds
- Independent deploys — Frontend doesn't break if backend changes
- Pure frontend devs — Clone and run, types are already there
Strategy 2: Gitignore Types
- Requires backend access during CI/CD builds
- Breaking changes propagate immediately
- Best for monorepos where FE/BE deploy together
Strategy 3: Point to Production
Frontend developers can sync from production without backend code access:
Using Types
Import synced types in your frontend. First, configure your tsconfig.json:
Then import your types:
typeowl/types that provides empty types before you run sync. After configuring your tsconfig paths, the placeholder gets overridden with your actual generated types.
TypeScript Setup
Configure your tsconfig.json to enable type imports:
Now you can import your types:
Building an API Client
Create a fully typed API client using the generated ApiEndpoints:
Multiple Backends
For microservices, configure multiple resolvers:
Security
Protect TypeOwl endpoints in production:
Watch Mode
Auto-sync types during development using the CLI:
concurrently to run watch mode alongside your dev server:
"dev:watch": "concurrently \"npx typeowl watch\" \"vite\""