Skip to content

Commit 0fc83f8

Browse files
authored
Fix types for PatchRoutesOnNavigationFunction (#11976)
1 parent 19ba686 commit 0fc83f8

File tree

6 files changed

+31
-16
lines changed

6 files changed

+31
-16
lines changed

packages/react-router/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export type {
7878
NavigateOptions,
7979
Navigator,
8080
NonIndexRouteObject,
81+
PatchRoutesOnNavigationFunction,
82+
PatchRoutesOnNavigationFunctionArgs,
8183
RouteMatch,
8284
RouteObject,
8385
} from "./lib/context";
@@ -93,7 +95,6 @@ export type {
9395
RouterProps,
9496
RouterProviderProps,
9597
RoutesProps,
96-
PatchRoutesOnNavigationFunction as PatchRoutesOnNavigationFunction,
9798
} from "./lib/components";
9899
export type { NavigateFunction } from "./lib/hooks";
99100
export {

packages/react-router/lib/components.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import type {
2323
} from "./router/router";
2424
import { createRouter } from "./router/router";
2525
import type {
26-
AgnosticPatchRoutesOnNavigationFunction,
2726
DataStrategyFunction,
2827
LazyRouteFunction,
2928
TrackedPromise,
@@ -35,6 +34,7 @@ import type {
3534
IndexRouteObject,
3635
Navigator,
3736
NonIndexRouteObject,
37+
PatchRoutesOnNavigationFunction,
3838
RouteMatch,
3939
RouteObject,
4040
ViewTransitionContextObject,
@@ -130,9 +130,6 @@ export function mapRouteProperties(route: RouteObject) {
130130
return updates;
131131
}
132132

133-
export interface PatchRoutesOnNavigationFunction
134-
extends AgnosticPatchRoutesOnNavigationFunction<RouteMatch> {}
135-
136133
/**
137134
* @category Routers
138135
*/

packages/react-router/lib/context.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type {
1313
import type {
1414
AgnosticIndexRouteObject,
1515
AgnosticNonIndexRouteObject,
16+
AgnosticPatchRoutesOnNavigationFunction,
17+
AgnosticPatchRoutesOnNavigationFunctionArgs,
1618
AgnosticRouteMatch,
1719
LazyRouteFunction,
1820
TrackedPromise,
@@ -74,6 +76,12 @@ export interface RouteMatch<
7476

7577
export interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {}
7678

79+
export type PatchRoutesOnNavigationFunctionArgs =
80+
AgnosticPatchRoutesOnNavigationFunctionArgs<RouteObject, RouteMatch>;
81+
82+
export type PatchRoutesOnNavigationFunction =
83+
AgnosticPatchRoutesOnNavigationFunction<RouteObject, RouteMatch>;
84+
7785
export interface DataRouterContextObject
7886
// Omit `future` since those can be pulled from the `router`
7987
// `NavigationContext` needs future since it doesn't have a `router` in all cases

packages/react-router/lib/dom/lib.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ import {
6464
mergeRefs,
6565
usePrefetchBehavior,
6666
} from "./ssr/components";
67-
import type { PatchRoutesOnNavigationFunction } from "../components";
6867
import { Router, mapRouteProperties } from "../components";
69-
import type { RouteObject, NavigateOptions } from "../context";
68+
import type {
69+
RouteObject,
70+
NavigateOptions,
71+
PatchRoutesOnNavigationFunction,
72+
} from "../context";
7073
import {
7174
DataRouterContext,
7275
DataRouterStateContext,

packages/react-router/lib/dom/ssr/fog-of-war.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import type { PatchRoutesOnNavigationFunction } from "../../components";
2+
import type { PatchRoutesOnNavigationFunction } from "../../context";
33
import type { Router as RemixRouter } from "../../router/router";
44
import { matchRoutes } from "../../router/utils";
55
import type { AssetsManifest } from "./entry";

packages/react-router/lib/router/utils.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,21 @@ export interface DataStrategyFunction {
223223
(args: DataStrategyFunctionArgs): Promise<Record<string, DataStrategyResult>>;
224224
}
225225

226-
export interface AgnosticPatchRoutesOnNavigationFunction<
226+
export type AgnosticPatchRoutesOnNavigationFunctionArgs<
227+
O extends AgnosticRouteObject = AgnosticRouteObject,
227228
M extends AgnosticRouteMatch = AgnosticRouteMatch
228-
> {
229-
(opts: {
230-
path: string;
231-
matches: M[];
232-
patch: (routeId: string | null, children: AgnosticRouteObject[]) => void;
233-
}): void | Promise<void>;
234-
}
229+
> = {
230+
path: string;
231+
matches: M[];
232+
patch: (routeId: string | null, children: O[]) => void;
233+
};
234+
235+
export type AgnosticPatchRoutesOnNavigationFunction<
236+
O extends AgnosticRouteObject = AgnosticRouteObject,
237+
M extends AgnosticRouteMatch = AgnosticRouteMatch
238+
> = (
239+
opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>
240+
) => void | Promise<void>;
235241

236242
/**
237243
* Function provided by the framework-aware layers to set any framework-specific

0 commit comments

Comments
 (0)