Using pnpm
Due to pnpm’s strict dependency isolation,@inertiajs/core is not accessible at node_modules/@inertiajs/core. Instead, it’s nested inside .pnpm/, which prevents TypeScript module augmentation from resolving the module.
You may fix this by configuring pnpm to hoist the package. Add the following to your .npmrc file and run pnpm install.
@inertiajs/core as a direct dependency in your project.
Global Configuration
You may configure Inertia’s types globally by augmenting theInertiaConfig interface in the @inertiajs/core module. This is typically done in a global.d.ts file in your project’s root or types directory.
For module augmentation to work, your
tsconfig.json needs to include .d.ts files. Make sure a pattern like "resources/js/**/*.d.ts" is present in the include array, adjusted to match your project’s directory structure.Shared Page Props
ThesharedPageProps option defines the type of data that is shared with every page in your application. With this configuration, page.props.auth and page.props.appName will be properly typed everywhere.
Flash Data
TheflashDataType option defines the type of flash data in your application.
Error Values
By default, validation error values are typed asstring. You may configure TypeScript to expect arrays instead for multiple errors per field.
The next version of Laravel Wayfinder may automatically generate these types for you by analyzing your Laravel application. It generates TypeScript types for shared props, page props, form requests, and Eloquent models. This version is currently in beta.
Page Components
You may type theimport.meta.glob result for better type safety when resolving page components.
Page Props
You may type page-specific props by passing a generic tousePage(). These are merged with your global sharedPageProps, giving you autocomplete and type checking for both shared and page-specific data.
Form Helper
The form helper accepts a generic type parameter for type-safe form data and error handling. This provides autocomplete for form fields and errors, and prevents typos in field names.Nested Data and Arrays
Form types fully support nested objects and arrays. You may access and update nested fields using dot notation, and error keys are automatically typed to match.Remembering State
TheuseRemember hook accepts a generic type parameter for type-safe local state persistence, providing autocomplete and ensuring values match the expected types.
Restoring State
Therouter.restore() method accepts a generic for typing state restored from history.
Router Requests
Router methods accept a generic for typing request data, providing type checking for the data being sent.Scoped Flash Data
Therouter.flash() method accepts a generic for typing page or section-specific flash data, separate from the global flashDataType configuration.
Client-Side Visits
Therouter.push() and router.replace() methods accept a generic for typing client-side visit props.