Skip to content

Commit 7c2d155

Browse files
Merge pull request #14 from laravel/restore-literal-types
Return literal HTTP methods, fixes Inertia TypeScript error
2 parents 99fd329 + 7943e17 commit 7c2d155

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

resources/function-arguments.blade.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ args{!! when($parameters->every->optional, '?') !!}: {
2424
@endif
2525
,
2626
@endif
27-
options?: { query?: QueryParams, mergeQuery?: QueryParams },
27+
options?: { query?: QueryParams, mergeQuery?: QueryParams }
2828
@endtrimDeadspace

resources/method.blade.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
@use('Illuminate\Support\HtmlString')
22
@include('wayfinder::docblock')
3-
{!! when(($export ?? true) && !$isInvokable, 'export ') !!}const {!! $method !!} = (@include('wayfinder::function-arguments')) => ({
3+
{!! when(($export ?? true) && !$isInvokable, 'export ') !!}const {!! $method !!} = (@include('wayfinder::function-arguments')): {
4+
url: string,
5+
method: @js($verbs->first()->actual),
6+
} => ({
47
url: {!! $method !!}.url({!! when($parameters->isNotEmpty(), 'args, ') !!}options),
58
method: @js($verbs->first()->actual),
69
})
@@ -67,15 +70,21 @@
6770

6871
@foreach ($verbs as $verb)
6972
@include('wayfinder::docblock')
70-
{!! $method !!}.{!! $verb->actual !!} = (@include('wayfinder::function-arguments')) => ({
73+
{!! $method !!}.{!! $verb->actual !!} = (@include('wayfinder::function-arguments')): {
74+
url: string,
75+
method: @js($verb->actual),
76+
} => ({
7177
url: {!! $method !!}.url({!! when($parameters->isNotEmpty(), 'args, ') !!}options),
7278
method: @js($verb->actual),
7379
})
7480

7581
@endforeach
7682
@if ($withForm)
7783
@include('wayfinder::docblock')
78-
const {!! $method !!}Form = (@include('wayfinder::function-arguments')) => ({
84+
const {!! $method !!}Form = (@include('wayfinder::function-arguments')): {
85+
action: string,
86+
method: @js($verbs->first()->formSafe),
87+
} => ({
7988
action: {!! $method !!}.url({!! when($parameters->isNotEmpty(), 'args, ') !!}@if ($verbs->first()->formSafe !== $verbs->first()->actual)
8089
{
8190
[options?.mergeQuery ? 'mergeQuery' : 'query']: {
@@ -91,7 +100,10 @@ options
91100

92101
@foreach ($verbs as $verb)
93102
@include('wayfinder::docblock')
94-
{!! $method !!}Form.{!! $verb->actual !!} = (@include('wayfinder::function-arguments')) => ({
103+
{!! $method !!}Form.{!! $verb->actual !!} = (@include('wayfinder::function-arguments')): {
104+
action: string,
105+
method: @js($verb->formSafe),
106+
} => ({
95107
action: {!! $method !!}.url({!! when($parameters->isNotEmpty(), 'args, ') !!}@if ($verb->formSafe !== $verb->actual)
96108
{
97109
[options?.mergeQuery ? 'mergeQuery' : 'query']: {

src/TypeScript.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static function trimDeadspace(string $view): string
1212
->replace('[ ', '[')
1313
->replace(' ]', ']')
1414
->replace(', }', ' }')
15+
->trim()
1516
->toString();
1617
}
1718

0 commit comments

Comments
 (0)