spatie/laravel-typescript-transformer
Generate TypeScript types from your Laravel/PHP code. Convert classes, DTOs and enums (with attributes) into accurate TS definitions, supporting nullable fields, complex/generic types, and even TypeScript function generation via a simple CLI/workflow.
method type from string to a literal union ('get' | 'post' | 'put' | 'patch' | 'delete'), directly addressing frontend framework compatibility (e.g., Inertia.js, Livewire). This aligns with type-driven development and reduces runtime assertions.httpMethodsPriority option enables explicit control over emitted methods, improving frontend type clarity by excluding non-standard methods (e.g., HEAD, OPTIONS) by default. Ideal for SPA/MPA projects where these methods are rarely used.HEAD) are supported via the new option.spatie/laravel-api-documentation) are still required for full API alignment.httpMethodsPriority). No breaking changes to existing type outputs.visit()).httpMethodsPriority, e.g., for GraphQL-like endpoints or custom verbs (e.g., ['get', 'post', 'head'])..d.ts files, but with refined type granularity.PURGE, SEARCH) must explicitly include them in httpMethodsPriority to avoid omission.strict: true) to avoid implicit any fallbacks.PATCH, PROPFIND) that must be preserved in generated types?httpMethodsPriority be hardcoded in config/typescript-transformer.php or dynamic (e.g., per-route)?HEAD for caching proxies)?strict: true in tsconfig.json? Literal unions may expose implicit any issues elsewhere.string fallback, how will legacy frontend code adapt?httpMethodsPriority?router.visit('/users', { method: 'get' })).httpMethodsPriority.config/typescript-transformer.php:
'http_methods_priority' => ['get', 'post', 'put', 'patch', 'delete'],
HEAD):
'http_methods_priority' => ['get', 'post', 'head'],
php artisan typescript-transformer:transform..d.ts files for correct method unions (e.g., method: 'get' | 'post').router.visit('/users', { method: 'get' }); // No cast needed
tsconfig.json has:
{
"strict": true,
"noImplicitAny": true
}
method unions in visit() calls.method: 'post').AxiosRequestConfig['method'].TransformClass) remain unaffected.composer require spatie/laravel-typescript-transformer --dev
php artisan vendor:publish --provider="Spatie\LaravelTypeScriptTransformer\TypeScriptTransformerServiceProvider".http_methods_priority in config/typescript-transformer.php.php artisan typescript-transformer:transform..d.ts files include literal method unions (e.g., method: 'get' | 'post').composer.json scripts (unchanged):
"post-update-cmd": ["@typescript-transformer:transform"]
tsc --noEmit).as const or type casts for HTTP methods.HEAD/OPTIONS reduces noise in .d.ts files.httpMethodsPriority centralizes control over emitted methods.method: string) may need updates.any issues in unrelated parts of the codebase.httpMethodsPriority.HEAD is omitted unexpectedly, check httpMethodsPriority config.tsconfig.json has strict: true to catch literal union mismatches.method: 'post').RouteDefinition['method'] is now a union).httpMethodsPriority.httpMethodsPriority filter reduces output size, improving build times.How can I help you explore Laravel packages today?