Skip to content

Commit d379ade

Browse files
Merge pull request #786 from bram-pkg/bram-pkg/fix-type-definition
Fix type definition for route() with only options
2 parents 11d61d0 + a1a2220 commit d379ade

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/js/index.d.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,26 +168,29 @@ interface Router {
168168
*/
169169
// Called with no arguments - returns a Router instance
170170
export function route(): Router;
171+
172+
// Called with configuration arguments only - returns a configured Router instance
173+
export function route(
174+
name: undefined,
175+
params: undefined,
176+
absolute?: boolean,
177+
config?: Config,
178+
): Router;
179+
171180
// Called with a route name and optional additional arguments - returns a URL string
172181
export function route<T extends RouteName>(
173182
name: T,
174183
params?: RouteParams<T> | undefined,
175184
absolute?: boolean,
176185
config?: Config,
177186
): string;
187+
178188
export function route<T extends RouteName>(
179189
name: T,
180190
params?: ParameterValue | undefined,
181191
absolute?: boolean,
182192
config?: Config,
183193
): string;
184-
// Called with configuration arguments only - returns a configured Router instance
185-
export function route(
186-
name: undefined,
187-
params: undefined,
188-
absolute?: boolean,
189-
config?: Config,
190-
): Router;
191194

192195
/**
193196
* Ziggy's Vue plugin.

tests/js/route.test-d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assertType } from 'vitest';
2-
import { route } from '../../src/js';
2+
import { Config, route, Router } from '../../src/js';
33

44
// Add generated routes to use for testing inside this file. In a real app these declarations
55
// would be in a separate file generated by running `php artisan ziggy:generate --types`.
@@ -97,3 +97,8 @@ assertType(route().current('posts.comments.show', { post: 2 }));
9797
assertType(route().current('posts.comments.show', 2));
9898
// assertType(route().current('posts.comments.show', [2])); // TODO shouldn't error, only one required param
9999
assertType(route().current('posts.comments.show', 'foo'));
100+
101+
// Test route function return types
102+
assertType<string>(route('optional', { maybe: 'foo' }));
103+
assertType<string>(route('optional', 'foo'));
104+
assertType<Router>(route(undefined, undefined, undefined, {} as Config));

0 commit comments

Comments
 (0)