Skip to main content
Kit can automatically generate TypeScript interfaces from your Rust InertiaProps structs, ensuring type safety between your backend and frontend.

Generating Types

Run the generate-types command:
This scans your Rust source files for #[derive(InertiaProps)] structs and generates TypeScript interfaces in frontend/src/types/inertia-props.ts.

How It Works

Given this Rust code:
Kit generates:

Type Mappings

Kit converts Rust types to TypeScript equivalents:

Using Generated Types

Import types in your React components:

Nested Structs

Nested structs are automatically included:
Generates:

Best Practices

Run After Schema Changes

Regenerate types whenever you modify props:

Add to Build Process

Include type generation in your development workflow:

Use Strict Mode

Enable strict TypeScript checking in tsconfig.json:

Handle Optional Values

Always handle null cases for Option<T> fields:

Workflow Integration

Development Workflow

  1. Define props in Rust controller
  2. Run kit generate-types
  3. Import types in React component
  4. Get full autocomplete and type checking

Example Workflow

FormRequest Types for Type-Safe Forms

FormRequests can also generate TypeScript types, enabling end-to-end type safety for form submissions.

Generating FormRequest Types

Add #[derive(InertiaProps)] to your FormRequest structs:
Run kit generate-types to generate:

Type-Safe Forms with Inertia

Use the generated type with Inertia’s <Form> component for the cleanest approach:
For more control over form state, use useForm with the generated types:

Benefits

  • Field name autocomplete: TypeScript suggests valid field names
  • Type checking: Catch type mismatches at compile time
  • Validation alignment: TypeScript types match Rust validation rules
  • Error handling: The errors object has matching field keys
For more information on requests and validation, see Requests.

Type-Safe Routes (Inertia v2+)

Kit generates type-safe route helpers that work natively with Inertia.js v2+ UrlMethodPair interface. This enables fully type-safe navigation without manually typing URLs or HTTP methods.

Generated Output

Running kit generate-types also generates frontend/src/types/routes.ts:

Usage with Inertia.js

The generated controllers object works directly with Inertia v2’s native APIs:

Path Parameters

Routes with path parameters like /users/{id} automatically generate typed parameter objects:

How Route Scanning Works

Kit scans your src/routes.rs file and extracts:
  1. HTTP method: get, post, put, patch, delete
  2. Path: Including path parameters like {id}
  3. Handler: Module and function name (e.g., controllers::user::show)
  4. Route name: Optional .name("route.name") suffix

Named Routes Lookup

Named routes are exported as a lookup object for easy access:

Benefits

Troubleshooting

Types Not Updating

If types aren’t reflecting your changes:
  1. Ensure structs have #[derive(InertiaProps)]
  2. Run kit generate-types again
  3. Restart your TypeScript language server

Missing Nested Types

For nested structs to be included, they must be:
  • Used in an InertiaProps struct
  • Have #[derive(Serialize)]

Type Errors

If you get type mismatches:
  • Check that Rust and TypeScript types align
  • Verify Option<T> handling (generates T | null)
  • Ensure vectors generate arrays (Vec<T>T[])

Summary

Generated Files

Features