spatie/laravel-typescript-transformer
Convert PHP classes, enums, and more into TypeScript types automatically in Laravel. Mark PHP code with attributes, handle complex types and generics, and generate TS-friendly definitions (and even functions) to keep frontend types in sync.
Build vs. Buy:
Adopt when:
Look elsewhere if:
For Executives:
"This package bridges Laravel’s PHP backend with TypeScript frontends by auto-generating type definitions for models, controllers, and routes. It eliminates manual type syncing—saving dev time and reducing API errors. For example, a User model with 20 fields generates a TypeScript interface instantly, ensuring frontend forms and API calls stay in sync. Watch mode even updates types in real-time as the backend evolves. Ideal for scaling teams where backend changes frequently impact frontend consumers."
For Engineers:
*"Spatie’s Laravel-TypeScript-Transformer lets you annotate PHP classes with [TypeScript] and generate matching TypeScript types via php artisan typescript:transform. Key features:
route<‘user.show’>(userId: number)).Collection<User> → User[]).php artisan typescript:watch to auto-regen types on file changes.For Frontend Teams: *"No more guessing API shapes! This tool auto-generates TypeScript types for your Laravel backend, so:
User model’s fields become a User interface.StoreUserRequest DTO becomes a TypeScript type with all validation rules. Works with Laravel’s built-in validation and Sanctum auth."*How can I help you explore Laravel packages today?