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:| Rust Type | TypeScript Type |
|---|---|
String, &str | string |
i8, i16, i32, i64 | number |
u8, u16, u32, u64 | number |
f32, f64 | number |
bool | boolean |
Option<T> | T | null |
Vec<T> | T[] |
HashMap<K, V> | Record<K, V> |
| Custom structs | Generated interface |
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
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[])
Summary
| Command | Description |
|---|---|
kit generate-types | Generate TypeScript from Rust props |
| Feature | Benefit |
|---|---|
| Automatic generation | No manual type definitions |
| Type safety | Catch errors at compile time |
| Autocomplete | Full IDE support |
| Nested types | Complex structures supported |