Skip to content

Commit 5dc7a0e

Browse files
Merge pull request #790 from simon-tma/patch-2
Only limit route names when calling route()
2 parents 72ebdb9 + 61bad11 commit 5dc7a0e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/js/index.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ type KnownRouteName = keyof RouteList;
1818
/**
1919
* A route name, or any string.
2020
*/
21-
type RouteName = TypeConfig extends { strictRouteNames: true }
22-
? KnownRouteName
23-
: KnownRouteName | (string & {});
21+
type RouteName = KnownRouteName | (string & {});
2422
// `(string & {})` prevents TypeScript from reducing this type to just `string`,
2523
// which would prevent intellisense from autocompleting known route names.
2624
// See https://stackoverflow.com/a/61048124/6484459.
2725

26+
/**
27+
* A valid route name to pass to `route()` to generate a URL.
28+
*/
29+
type ValidRouteName = TypeConfig extends { strictRouteNames: true } ? KnownRouteName : RouteName;
30+
2831
/**
2932
* Information about a single route parameter.
3033
*/
@@ -190,14 +193,14 @@ export function route(
190193
): Router;
191194

192195
// Called with a route name and optional additional arguments - returns a URL string
193-
export function route<T extends RouteName>(
196+
export function route<T extends ValidRouteName>(
194197
name: T,
195198
params?: RouteParams<T> | undefined,
196199
absolute?: boolean,
197200
config?: Config,
198201
): string;
199202

200-
export function route<T extends RouteName>(
203+
export function route<T extends ValidRouteName>(
201204
name: T,
202205
params?: ParameterValue | undefined,
203206
absolute?: boolean,

0 commit comments

Comments
 (0)