Download the PHP package isaiasg3/laravel-inertia-type-sync without Composer
On this page you can find all versions of the php package isaiasg3/laravel-inertia-type-sync. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download isaiasg3/laravel-inertia-type-sync
More information about isaiasg3/laravel-inertia-type-sync
Files in isaiasg3/laravel-inertia-type-sync
Package laravel-inertia-type-sync
Short Description Automatic End-to-End Type Safety between Laravel (FormRequests/JsonResources) and TypeScript for Inertia.js + Vue 3 apps.
License MIT
Informations about the package laravel-inertia-type-sync
laravel-inertia-type-sync
Automatic End-to-End Type Safety between Laravel and Inertia.js + Vue 3, without any additional PHP annotations.
The Problem
In a typical Inertia.js app, the contract between the backend and frontend lives in two completely separate places that are never validated against each other:
- The
FormRequest::rules()in PHP. - The types (or lack thereof) that the Vue component assumes when receiving
propsor building auseForm().
When someone adds a required field in the backend and forgets to update the frontend (or vice versa), the error only shows up in production, not at compile time. Tools like spatie/laravel-typescript-transformer solve this very well, but they require you to manually annotate every DTO or Resource with PHP attributes.
laravel-inertia-type-sync analyzes your code just as you write it — using Reflection over rules() and AST analysis over toArray() — and generates a single synchronized .d.ts file with a simple Artisan command.
Installation
You can install the package via Composer:
Optionally, you can publish the configuration file:
Check the config/inertia-type-sync.php file to adjust the scanning paths and your models' base namespace if it's different from App\Models.
Usage
Run the following command to generate your types:
This will generate a file at resources/js/types/generated.d.ts with a TypeScript interface for every FormRequest and JsonResource detected in your project:
In a Vue 3 component (Composition API)
Forms with useForm — Inertia's generic type validates every v-model against the generated interface:
Typed Props from a JsonResource:
Keeping the file synced automatically
Integrate the command into your usual workflow by adding it to your composer.json scripts:
This way, every time you run composer dump-autoload or install a new package, your TypeScript types will be automatically updated.
How it works under the hood
| PHP Source | Technique | Result |
|---|---|---|
FormRequest::rules() |
PHP Reflection + rule parser | Interface with primitive types, literal unions (in:), and nested arrays (items.*.sku) |
JsonResource::toArray() |
AST Analysis (nikic/php-parser) over the method's source code |
Interface with types inferred from Eloquent $casts, nested resources, and optional when()/whenLoaded() fields |
Known Limitations
- Properties within a
JsonResourcewithout an explicitly declared cast in the corresponding Eloquent model will be generated asunknown. - The AST analysis currently only evaluates a top-level
return [...]statement inside thetoArray()method.
Contributing
Pull Requests are welcome! Please run composer test and composer analyse before submitting your changes.
License
The MIT License (MIT).
All versions of laravel-inertia-type-sync with dependencies
illuminate/console Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^10.0|^11.0|^12.0|^13.0
symfony/finder Version ^6.0|^7.0|^8.0
nikic/php-parser Version ^5.0