Skip to main content

Typed Routes

Expo Router automatically generates TypeScript types for all your routes, providing type safety for navigation, parameters, and hrefs.

How It Works

When you start your development server, Expo Router analyzes your app directory and generates type definitions:
Types are automatically generated in node_modules/.expo/types and included in your project.

Type-Safe Hrefs

All routes are typed, providing autocomplete and type checking:

Type-Safe Parameters

Dynamic route parameters are automatically typed:
app/user/[id].tsx

Route Type Definition

Expo Router generates a type for all your routes:
From the source (typed-routes/types.ts:42-59):

Using Typed Routes

Router Navigation

useLocalSearchParams

useSegments

From the source (hooks.ts:150-165):

Type Generation

Automatic Generation

Types are generated when:
  1. Development server starts (npx expo start)
  2. Files in app directory change
  3. New routes are added or removed

Manual Generation

Force type regeneration:

CI/CD Type Checking

Generate types for CI/CD:

Configuration

TypeScript Config

Ensure your tsconfig.json includes:
tsconfig.json

IDE Setup

For best experience:
  1. VS Code: Install “TypeScript and JavaScript Language Features”
  2. Restart TS Server: Cmd/Ctrl + Shift + P → “TypeScript: Restart TS Server”
  3. Enable IntelliSense: Settings → “TypeScript › Suggest: Paths” (enabled)

Advanced Types

Generic Route Type

Create helper types for routes:

Route Parameters Type

Const Assertions

Use as const for literal types:

Common Patterns

Route Constants

Type Guards

Troubleshooting

Types Not Generated

Solution: Restart development server

TypeScript Errors

“Type ‘string’ is not assignable to type ‘Href’”
“Property does not exist on type”

IDE Not Showing Autocomplete

  1. Restart TypeScript server: Cmd/Ctrl + Shift + P → “TypeScript: Restart TS Server”
  2. Check TypeScript version: Should be 5.0 or higher
  3. Verify tsconfig.json includes .expo/types/**/*.ts
  4. Check Expo CLI version: Update to latest

Build Errors

If types work in development but fail in builds:
tsconfig.json

Best Practices

Always Type Parameters

Use Const Assertions

Create Route Constants

Validate Dynamic Routes

Migration Guide

From Untyped to Typed

Step 1: Start dev server
Step 2: Add types to parameters
Step 3: Update navigation
Step 4: Fix type errors Address any TypeScript errors revealed by type generation.

Next Steps

Dynamic Routes

Type dynamic route parameters

Navigation

Type-safe navigation methods

Deep Linking

Type-safe deep links

API Routes

Type-safe API endpoints