From 63fd733dc903299b3918c39df19103adf98e1b38 Mon Sep 17 00:00:00 2001 From: simon-tma Date: Tue, 19 Nov 2024 16:39:47 +1100 Subject: [PATCH 1/2] Only limit route names when calling route() 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()`. --- src/js/index.d.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/js/index.d.ts b/src/js/index.d.ts index ddd20f8f..aedb4694 100644 --- a/src/js/index.d.ts +++ b/src/js/index.d.ts @@ -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. */ @@ -187,14 +192,14 @@ export function route( ): Router; // Called with a route name and optional additional arguments - returns a URL string -export function route( +export function route( name: T, params?: RouteParams | undefined, absolute?: boolean, config?: Config, ): string; -export function route( +export function route( name: T, params?: ParameterValue | undefined, absolute?: boolean, From 61bad11d39d1727bf23634b827dfa50bc085cafc Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Wed, 22 Jan 2025 18:43:51 -0500 Subject: [PATCH 2/2] Formatting --- src/js/index.d.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/js/index.d.ts b/src/js/index.d.ts index aedb4694..3a365387 100644 --- a/src/js/index.d.ts +++ b/src/js/index.d.ts @@ -26,11 +26,9 @@ type RouteName = KnownRouteName | (string & {}); // See https://stackoverflow.com/a/61048124/6484459. /** - * Valid route names to pass to route(). + * A valid route name to pass to `route()` to generate a URL. */ -type AllowedRouteName = TypeConfig extends { strictRouteNames: true } - ? KnownRouteName - : RouteName; +type ValidRouteName = TypeConfig extends { strictRouteNames: true } ? KnownRouteName : RouteName; /** * Information about a single route parameter. @@ -192,14 +190,14 @@ export function route( ): Router; // Called with a route name and optional additional arguments - returns a URL string -export function route( +export function route( name: T, params?: RouteParams | undefined, absolute?: boolean, config?: Config, ): string; -export function route( +export function route( name: T, params?: ParameterValue | undefined, absolute?: boolean,