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 and prioritize HTTP methods (#83)Fixes #76. The generated RouteDefinition and MethodRoute types previously declared method: string, which forced casts when handing the result to libraries like Inertia that expect 'get' | 'post' | 'put' | 'patch' | 'delete'. The output now uses a literal union, so:
router.visit(SomeController.update(), { data: { ... } });
just works. On top of that, LaravelControllerTransformedProvider accepts a new httpMethodsPriority argument that doubles as both filter and sort order. Methods absent from the list are dropped from the output, and the ones that survive are emitted in list order. The default is ['get', 'post', 'put', 'patch', 'delete'], so HEAD and OPTIONS (auto-registered by Laravel for every GET route, never invoked by SPAs) are no longer emitted.
If you actually relied on the HEAD entries, pass a custom list including 'head'. Thanks @rubenvanassche.
A round of bug fixes for route generation, laravel-data integration, and the writer.
name_mapping_strategy.output config (#81)If your config/data.php looked like this:
'name_mapping_strategy' => [
'output' => SnakeCaseMapper::class,
],
The transformer was silently ignoring it and emitting camelCase keys. The processor now resolves property output names through DataConfig::getDataClass(), so the global mapper, class level, and property level MapName / MapOutputName attributes all flow through one source. Thanks @rubenvanassche.
route() helper producing // for the root route (#82)Route::get('/') produced route('home') === '//' because Laravel's $route->uri returns / for the root and bare paths (without a leading slash) for everything else. The runtime helper then prepended another /. After this fix:
route('home'); // '/' (was '//')
route('help.index'); // '/help' (unchanged)
Thanks @rubenvanassche.
Watching routes with any RouteFilter configured crashed with Command array element 4 contains a null byte. PHP's serialize() emits \0*\0 markers for protected properties, and Symfony Process rejects command arguments that contain null bytes. Every shipped filter (NamedRouteFilter, ControllerRouteFilter, ClosureRouteFilter) hit this. The serialized payload is now base64 encoded across the process boundary. Thanks @rubenvanassche.
Controller type generation now uses is_a() instead of in_array() when checking for data collection classes, so subclasses of DataCollection are recognised. buildActionCallExpression was also renamed to buildActionCallNode to make it overridable. Thanks @iamrgroot.
GlobalNamespaceWriter producing a broken path when given an absolute path (#79)Passing an absolute path resulted in the output directory being concatenated in front of it:
resources/js/generated/home/user/project/resources/types/generated.d.ts
Pass a relative filename instead, and the writer will resolve it correctly against the configured output directory. Thanks @A909M.
name_mapping_strategy.output config by @rubenvanassche in https://github.com/spatie/laravel-typescript-transformer/pull/81route() helper producing // for the root route by @rubenvanassche in https://github.com/spatie/laravel-typescript-transformer/pull/82GlobalNamespaceWriter producing a broken path when given an absolute path by @A909M in https://github.com/spatie/laravel-typescript-transformer/pull/79Full Changelog: https://github.com/spatie/laravel-typescript-transformer/compare/3.0.3...3.0.4
Full Changelog: https://github.com/spatie/laravel-typescript-transformer/compare/3.0.2...3.0.3
typescript:install command stub (#69)
Spatie\TypeScriptTransformer\Laravel\TypeScriptTransformerApplicationServiceProvider → Spatie\LaravelTypeScriptTransformer\TypeScriptTransformerApplicationServiceProviderNamespaceWriter → GlobalNamespaceWriterThis is a major release built on top of the completely rewritten spatie/typescript-transformer v3.
spatie/typescript-transformer ^3.0Since it is a complete rewrite, we recommend reading through the new docs and updating your application accodingly.
Full Changelog: https://github.com/spatie/laravel-typescript-transformer/compare/2.5.1...2.5.2
Allow Laravel 12
Full Changelog: https://github.com/spatie/laravel-typescript-transformer/compare/2.5.0...2.5.1
nullToOptional by @innocenzi in https://github.com/spatie/laravel-typescript-transformer/pull/46Full Changelog: https://github.com/spatie/laravel-typescript-transformer/compare/2.4.1...2.5.0
Full Changelog: https://github.com/spatie/laravel-typescript-transformer/compare/2.4.0...2.4.1
Full Changelog: https://github.com/spatie/laravel-typescript-transformer/compare/2.3.2...2.4.0
Full Changelog: https://github.com/spatie/laravel-typescript-transformer/compare/2.1.6...2.1.7
SpatieEnumTransformer to the typescript-transformer packageFull Changelog: https://github.com/spatie/laravel-typescript-transformer/compare/2.1.1...2.1.2
How can I help you explore Laravel packages today?