Skip to content

Commit

Permalink
Only limit route names when calling route()
Browse files Browse the repository at this point in the history
When `strictRouteNames` is set, we still need to allow wildcard route names to be passed to `current()` and potentially invalid route names to be passed to `has()`.
  • Loading branch information
simon-tma authored Nov 19, 2024
1 parent e5d51d2 commit 63fd733
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ type KnownRouteName = keyof RouteList;
/**
* A route name, or any string.
*/
type RouteName = TypeConfig extends { strictRouteNames: true }
? KnownRouteName
: KnownRouteName | (string & {});
type RouteName = KnownRouteName | (string & {});
// `(string & {})` prevents TypeScript from reducing this type to just `string`,
// which would prevent intellisense from autocompleting known route names.
// See https://stackoverflow.com/a/61048124/6484459.

/**
* Valid route names to pass to route().
*/
type AllowedRouteName = TypeConfig extends { strictRouteNames: true }
? KnownRouteName
: RouteName;

/**
* Information about a single route parameter.
*/
Expand Down Expand Up @@ -187,14 +192,14 @@ export function route(
): Router;

// Called with a route name and optional additional arguments - returns a URL string
export function route<T extends RouteName>(
export function route<T extends AllowedRouteName>(
name: T,
params?: RouteParams<T> | undefined,
absolute?: boolean,
config?: Config,
): string;

export function route<T extends RouteName>(
export function route<T extends AllowedRouteName>(
name: T,
params?: ParameterValue | undefined,
absolute?: boolean,
Expand Down

0 comments on commit 63fd733

Please sign in to comment.