Skip to content

Commit 5ac9d27

Browse files
Add types to NavigationTarget (#14167)
* fix #14048 * Create four-suns-refuse.md * Apply suggestions from code review * regenerate --------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent 90fb567 commit 5ac9d27

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

.changeset/four-suns-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sveltejs/kit": feat
3+
---
4+
5+
feat: add `RouteId` and `RouteParams` to NavigationTarget interface

packages/kit/src/exports/public.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,20 +1020,23 @@ export interface NavigationEvent<
10201020
/**
10211021
* Information about the target of a specific navigation.
10221022
*/
1023-
export interface NavigationTarget {
1023+
export interface NavigationTarget<
1024+
Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1025+
RouteId extends AppRouteId | null = AppRouteId | null
1026+
> {
10241027
/**
10251028
* Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
10261029
* Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
10271030
*/
1028-
params: Record<string, string> | null;
1031+
params: Params | null;
10291032
/**
10301033
* Info about the target route
10311034
*/
10321035
route: {
10331036
/**
10341037
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
10351038
*/
1036-
id: string | null;
1039+
id: RouteId | null;
10371040
};
10381041
/**
10391042
* The URL that is navigated to

packages/kit/types/index.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,20 +997,23 @@ declare module '@sveltejs/kit' {
997997
/**
998998
* Information about the target of a specific navigation.
999999
*/
1000-
export interface NavigationTarget {
1000+
export interface NavigationTarget<
1001+
Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1002+
RouteId extends AppRouteId | null = AppRouteId | null
1003+
> {
10011004
/**
10021005
* Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
10031006
* Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
10041007
*/
1005-
params: Record<string, string> | null;
1008+
params: Params | null;
10061009
/**
10071010
* Info about the target route
10081011
*/
10091012
route: {
10101013
/**
10111014
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
10121015
*/
1013-
id: string | null;
1016+
id: RouteId | null;
10141017
};
10151018
/**
10161019
* The URL that is navigated to

0 commit comments

Comments
 (0)