From 26e44c601c98555800b30bf9682035d63cf198c3 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Mon, 21 Nov 2022 12:21:57 +0000 Subject: [PATCH] Relax vendored types. --- packages/react/src/types.ts | 74 ++++++++-------------- packages/react/test/reactrouterv6.test.tsx | 3 +- 2 files changed, 29 insertions(+), 48 deletions(-) diff --git a/packages/react/src/types.ts b/packages/react/src/types.ts index c61e1e119801..01031efba452 100644 --- a/packages/react/src/types.ts +++ b/packages/react/src/types.ts @@ -1,11 +1,16 @@ +// Disabling `no-explicit-any` for the whole file as `any` has became common requirement. +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Transaction, TransactionContext } from '@sentry/types'; -export type Action = 'PUSH' | 'REPLACE' | 'POP'; +export enum Action { + Pop = 'POP', + Push = 'PUSH', + Replace = 'REPLACE', +} export type Location = { pathname: string; action?: Action; - // eslint-disable-next-line @typescript-eslint/no-explicit-any } & Record; export type ReactRouterInstrumentation = ( @@ -19,7 +24,7 @@ export interface NonIndexRouteObject { caseSensitive?: boolean; children?: RouteObject[]; element?: React.ReactNode | null; - index?: false; + index?: any; path?: string; } @@ -27,7 +32,7 @@ export interface IndexRouteObject { caseSensitive?: boolean; children?: undefined; element?: React.ReactNode | null; - index: true; + index: any; path?: string; } @@ -69,9 +74,7 @@ export type UseNavigationType = () => Action; // For both of these types, use `any` instead of `RouteObject[]` or `RouteMatch[]`. // Have to do this so we maintain backwards compatability between // react-router > 6.0.0 and >= 6.4.2. -// eslint-disable-next-line @typescript-eslint/no-explicit-any export type RouteObjectArrayAlias = any; -// eslint-disable-next-line @typescript-eslint/no-explicit-any export type RouteMatchAlias = any; export type CreateRoutesFromChildren = (children: JSX.Element[]) => RouteObjectArrayAlias; export type MatchRoutes = (routes: RouteObjectArrayAlias, location: Location) => RouteMatchAlias[] | null; @@ -104,15 +107,9 @@ declare type AgnosticBaseRouteObject = { handle?: any; }; -export declare type AgnosticIndexRouteObject = AgnosticBaseRouteObject & { - children?: undefined; - index: true; -}; +export declare type AgnosticIndexRouteObject = AgnosticBaseRouteObject & Record; -export declare type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & { - children?: AgnosticRouteObject[]; - index?: false; -}; +export declare type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & Record; export declare type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & { id: string; @@ -183,50 +180,39 @@ declare type SubmissionNavigateOptions = { }; export interface RouterInit { - basename?: string; + basename: string; routes: AgnosticRouteObject[]; history: History; hydrationData?: HydrationState; } export type NavigationStates = { - Idle: { - state: 'idle'; - location: undefined; - formMethod: undefined; - formAction: undefined; - formEncType: undefined; - formData: undefined; - }; - Loading: { - state: 'loading'; - location: Location; - formMethod: FormMethod | undefined; - formAction: string | undefined; - formEncType: FormEncType | undefined; - formData: FormData | undefined; - }; - Submitting: { - state: 'submitting'; - location: Location; - formMethod: FormMethod; - formAction: string; - formEncType: FormEncType; - formData: FormData; - }; + Idle: any; + Loading: any; + Submitting: any; }; export type Navigation = NavigationStates[keyof NavigationStates]; +export type RouteData = any; +export type Fetcher = any; + export interface RouterState { historyAction: Action; - location: Location; + location: any; matches: AgnosticDataRouteMatch[]; initialized: boolean; navigation: Navigation; + restoreScrollPosition: number | false | null; + preventScrollReset: boolean; + revalidation: any; + loaderData: RouteData; + actionData: RouteData | null; + errors: RouteData | null; + fetchers: Map; } export interface Router { - basename: string; + basename: string | undefined; state: RouterState; routes: AgnosticDataRouteObject[]; _internalFetchControllers: any; @@ -248,8 +234,4 @@ export interface Router { dispose(): void; } -export type CreateRouterFunction = ( - routes: RouteObject[], - // eslint-disable-next-line @typescript-eslint/no-explicit-any - opts?: any, -) => Router; +export type CreateRouterFunction = (routes: RouteObject[], opts?: any) => Router; diff --git a/packages/react/test/reactrouterv6.test.tsx b/packages/react/test/reactrouterv6.test.tsx index c51541366592..95fad2a33f1d 100644 --- a/packages/react/test/reactrouterv6.test.tsx +++ b/packages/react/test/reactrouterv6.test.tsx @@ -14,8 +14,7 @@ import { useNavigationType, useRoutes, } from 'react-router-6'; - -import { createMemoryRouter, RouterProvider, Navigate as Navigate_6_4 } from 'react-router-6.4'; +import { createMemoryRouter, Navigate as Navigate_6_4,RouterProvider } from 'react-router-6.4'; import { reactRouterV6Instrumentation, wrapCreateBrowserRouter } from '../src'; import { withSentryReactRouterV6Routing, wrapUseRoutes } from '../src/reactrouterv6';