Skip to content

Commit

Permalink
Merge pull request #790 from simon-tma/patch-2
Browse files Browse the repository at this point in the history
Only limit route names when calling route()
  • Loading branch information
bakerkretzmar authored Jan 22, 2025
2 parents 72ebdb9 + 61bad11 commit 5dc7a0e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ 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.

/**
* A valid route name to pass to `route()` to generate a URL.
*/
type ValidRouteName = TypeConfig extends { strictRouteNames: true } ? KnownRouteName : RouteName;

/**
* Information about a single route parameter.
*/
Expand Down Expand Up @@ -190,14 +193,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 ValidRouteName>(
name: T,
params?: RouteParams<T> | undefined,
absolute?: boolean,
config?: Config,
): string;

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

0 comments on commit 5dc7a0e

Please sign in to comment.