Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ type RouteName = KnownRouteName | (string & {});
// which would prevent intellisense from autocompleting known route names.
// See https://stackoverflow.com/a/61048124/6484459.

/**
* A generated route URL string.
*/
export type RouteUrl = string;

/**
* A valid route name to pass to `route()` to generate a URL.
*/
Expand Down Expand Up @@ -201,14 +206,14 @@ export function route<T extends ValidRouteName>(
params?: RouteParams<T> | undefined,
absolute?: boolean,
config?: Config,
): string;
): RouteUrl;

export function route<T extends ValidRouteName>(
name: T,
params?: ParameterValue | undefined,
absolute?: boolean,
config?: Config,
): string;
): RouteUrl;

/**
* Ziggy's Vue plugin.
Expand Down
3 changes: 2 additions & 1 deletion tests/js/route.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertType } from 'vitest';
import { Config, route, Router } from '../../src/js';
import { Config, route, Router, RouteUrl } from '../../src/js';

// Add generated routes to use for testing inside this file. In a real app these declarations
// would be in a separate file generated by running `php artisan ziggy:generate --types`.
Expand Down Expand Up @@ -111,6 +111,7 @@ assertType(route().current('posts.comments.show', 'foo'));
// Test route function return types
assertType<string>(route('optional', { maybe: 'foo' }));
assertType<string>(route('optional', 'foo'));
assertType<RouteUrl>(route('posts.comments.show', 'foo'));
assertType<Router>(route(undefined, undefined, undefined, {} as Config));

// Uncomment to test strict route name checking - invalid route names in this file should error
Expand Down
Loading