Skip to content

Commit 26e44c6

Browse files
committed
Relax vendored types.
1 parent a3b39b7 commit 26e44c6

File tree

2 files changed

+29
-48
lines changed

2 files changed

+29
-48
lines changed

packages/react/src/types.ts

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
// Disabling `no-explicit-any` for the whole file as `any` has became common requirement.
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
13
import { Transaction, TransactionContext } from '@sentry/types';
24

3-
export type Action = 'PUSH' | 'REPLACE' | 'POP';
5+
export enum Action {
6+
Pop = 'POP',
7+
Push = 'PUSH',
8+
Replace = 'REPLACE',
9+
}
410

511
export type Location = {
612
pathname: string;
713
action?: Action;
8-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
914
} & Record<string, any>;
1015

1116
export type ReactRouterInstrumentation = <T extends Transaction>(
@@ -19,15 +24,15 @@ export interface NonIndexRouteObject {
1924
caseSensitive?: boolean;
2025
children?: RouteObject[];
2126
element?: React.ReactNode | null;
22-
index?: false;
27+
index?: any;
2328
path?: string;
2429
}
2530

2631
export interface IndexRouteObject {
2732
caseSensitive?: boolean;
2833
children?: undefined;
2934
element?: React.ReactNode | null;
30-
index: true;
35+
index: any;
3136
path?: string;
3237
}
3338

@@ -69,9 +74,7 @@ export type UseNavigationType = () => Action;
6974
// For both of these types, use `any` instead of `RouteObject[]` or `RouteMatch[]`.
7075
// Have to do this so we maintain backwards compatability between
7176
// react-router > 6.0.0 and >= 6.4.2.
72-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7377
export type RouteObjectArrayAlias = any;
74-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7578
export type RouteMatchAlias = any;
7679
export type CreateRoutesFromChildren = (children: JSX.Element[]) => RouteObjectArrayAlias;
7780
export type MatchRoutes = (routes: RouteObjectArrayAlias, location: Location) => RouteMatchAlias[] | null;
@@ -104,15 +107,9 @@ declare type AgnosticBaseRouteObject = {
104107
handle?: any;
105108
};
106109

107-
export declare type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
108-
children?: undefined;
109-
index: true;
110-
};
110+
export declare type AgnosticIndexRouteObject = AgnosticBaseRouteObject & Record<string, any>;
111111

112-
export declare type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
113-
children?: AgnosticRouteObject[];
114-
index?: false;
115-
};
112+
export declare type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & Record<string, any>;
116113

117114
export declare type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
118115
id: string;
@@ -183,50 +180,39 @@ declare type SubmissionNavigateOptions = {
183180
};
184181

185182
export interface RouterInit {
186-
basename?: string;
183+
basename: string;
187184
routes: AgnosticRouteObject[];
188185
history: History;
189186
hydrationData?: HydrationState;
190187
}
191188

192189
export type NavigationStates = {
193-
Idle: {
194-
state: 'idle';
195-
location: undefined;
196-
formMethod: undefined;
197-
formAction: undefined;
198-
formEncType: undefined;
199-
formData: undefined;
200-
};
201-
Loading: {
202-
state: 'loading';
203-
location: Location;
204-
formMethod: FormMethod | undefined;
205-
formAction: string | undefined;
206-
formEncType: FormEncType | undefined;
207-
formData: FormData | undefined;
208-
};
209-
Submitting: {
210-
state: 'submitting';
211-
location: Location;
212-
formMethod: FormMethod;
213-
formAction: string;
214-
formEncType: FormEncType;
215-
formData: FormData;
216-
};
190+
Idle: any;
191+
Loading: any;
192+
Submitting: any;
217193
};
218194

219195
export type Navigation = NavigationStates[keyof NavigationStates];
220196

197+
export type RouteData = any;
198+
export type Fetcher = any;
199+
221200
export interface RouterState {
222201
historyAction: Action;
223-
location: Location;
202+
location: any;
224203
matches: AgnosticDataRouteMatch[];
225204
initialized: boolean;
226205
navigation: Navigation;
206+
restoreScrollPosition: number | false | null;
207+
preventScrollReset: boolean;
208+
revalidation: any;
209+
loaderData: RouteData;
210+
actionData: RouteData | null;
211+
errors: RouteData | null;
212+
fetchers: Map<string, Fetcher>;
227213
}
228214
export interface Router {
229-
basename: string;
215+
basename: string | undefined;
230216
state: RouterState;
231217
routes: AgnosticDataRouteObject[];
232218
_internalFetchControllers: any;
@@ -248,8 +234,4 @@ export interface Router {
248234
dispose(): void;
249235
}
250236

251-
export type CreateRouterFunction = (
252-
routes: RouteObject[],
253-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
254-
opts?: any,
255-
) => Router;
237+
export type CreateRouterFunction = (routes: RouteObject[], opts?: any) => Router;

packages/react/test/reactrouterv6.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import {
1414
useNavigationType,
1515
useRoutes,
1616
} from 'react-router-6';
17-
18-
import { createMemoryRouter, RouterProvider, Navigate as Navigate_6_4 } from 'react-router-6.4';
17+
import { createMemoryRouter, Navigate as Navigate_6_4,RouterProvider } from 'react-router-6.4';
1918

2019
import { reactRouterV6Instrumentation, wrapCreateBrowserRouter } from '../src';
2120
import { withSentryReactRouterV6Routing, wrapUseRoutes } from '../src/reactrouterv6';

0 commit comments

Comments
 (0)