InertiaProps structs, ensuring type safety between your backend and frontend.
Generating Types
Run the generate-types command:#[derive(InertiaProps)] structs and generates TypeScript interfaces in frontend/src/types/inertia-props.ts.
How It Works
Given this Rust code: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: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 intsconfig.json:
Handle Optional Values
Always handlenull cases for Option<T> fields:
Workflow Integration
Development Workflow
- Define props in Rust controller
- Run
kit generate-types - Import types in React component
- 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:
kit generate-types to generate:
Type-Safe Forms with Inertia
Use the generated type with Inertia’s<Form> component for the cleanest approach:
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
errorsobject 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
Runningkit generate-types also generates frontend/src/types/routes.ts:
Usage with Inertia.js
The generatedcontrollers 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 yoursrc/routes.rs file and extracts:
- HTTP method:
get,post,put,patch,delete - Path: Including path parameters like
{id} - Handler: Module and function name (e.g.,
controllers::user::show) - 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:- Ensure structs have
#[derive(InertiaProps)] - Run
kit generate-typesagain - Restart your TypeScript language server
Missing Nested Types
For nested structs to be included, they must be:- Used in an
InertiaPropsstruct - Have
#[derive(Serialize)]
Type Errors
If you get type mismatches:- Check that Rust and TypeScript types align
- Verify
Option<T>handling (generatesT | null) - Ensure vectors generate arrays (
Vec<T>→T[])