Skip to content

Commit

Permalink
ref(react-router): Make RouteProps typing more generic (#3570)
Browse files Browse the repository at this point in the history
Previously we copied over the typings for a react-router Route props.
This means though that when the react-router updates it's types,
there is a chance our types will break. To avoid this in the future,
this patch removes the RouteProps typing and uses a plain
`Record<string, any>` type instead.

The props we do leverage from the RouteProps have checks in the code
and there are tests covering that the RouteProps properties exist,
so making the type more generic is not that risky.
  • Loading branch information
AbhiPrasad authored May 19, 2021
1 parent c3b1bb5 commit e7f5255
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
4 changes: 2 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"@types/hoist-non-react-statics": "^3.3.1",
"@types/react": "^17.0.3",
"@types/react-router-3": "npm:@types/react-router@3.0.24",
"@types/react-router-4": "npm:@types/react-router@5.1.13",
"@types/react-router-5": "npm:@types/react-router@5.1.13",
"@types/react-router-4": "npm:@types/react-router@5.1.14",
"@types/react-router-5": "npm:@types/react-router@5.1.14",
"eslint": "7.6.0",
"eslint-plugin-react": "^7.20.5",
"eslint-plugin-react-hooks": "^4.0.8",
Expand Down
16 changes: 1 addition & 15 deletions packages/react/src/reactrouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ export type RouteConfig = {
routes?: RouteConfig[];
};

interface RouteProps {
[propName: string]: any;
location?: Location;
component?: React.ComponentType<any> | React.ComponentType<any>;
render?: (props: any) => React.ReactNode;
children?: ((props: any) => React.ReactNode) | React.ReactNode;
path?: string | string[];
exact?: boolean;
sensitive?: boolean;
strict?: boolean;
}

type MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null;
/* eslint-enable @typescript-eslint/no-explicit-any */

Expand Down Expand Up @@ -148,9 +136,7 @@ function computeRootMatch(pathname: string): Match {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function withSentryRouting<P extends RouteProps & Record<string, any>>(
Route: React.ComponentType<P>,
): React.FC<P> {
export function withSentryRouting<P extends Record<string, any>>(Route: React.ComponentType<P>): React.FC<P> {
const componentDisplayName = Route.displayName || Route.name;

const WrappedRoute: React.FC<P> = (props: P) => {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3300,10 +3300,10 @@
"@types/history" "^3"
"@types/react" "*"

"@types/react-router-4@npm:@types/react-router@5.1.13", "@types/react-router-5@npm:@types/react-router@5.1.13":
version "5.1.13"
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-5.1.13.tgz#051c0d229bd48ad90558a1db500708127cc512f7"
integrity sha512-ZIuaO9Yrln54X6elg8q2Ivp6iK6p4syPsefEYAhRDAoqNh48C8VYUmB9RkXjKSQAJSJV0mbIFCX7I4vZDcHrjg==
"@types/react-router-4@npm:@types/react-router@5.1.14", "@types/react-router-5@npm:@types/react-router@5.1.14":
version "5.1.14"
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-5.1.14.tgz#e0442f4eb4c446541ad7435d44a97f8fe6df40da"
integrity sha512-LAJpqYUaCTMT2anZheoidiIymt8MuX286zoVFPM3DVb23aQBH0mAkFvzpd4LKqiolV8bBtZWT5Qp7hClCNDENw==
dependencies:
"@types/history" "*"
"@types/react" "*"
Expand Down Expand Up @@ -14454,7 +14454,7 @@ neo-async@^2.5.0, neo-async@^2.6.0, neo-async@^2.6.1, neo-async@^2.6.2:
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==

next@^10.1.3:
next@10.1.3:
version "10.1.3"
resolved "https://registry.yarnpkg.com/next/-/next-10.1.3.tgz#e26e8371343a42bc2ba9be5cb253a7d324d03673"
integrity sha512-8Jf38F+s0YcXXkJGF5iUxOqSmbHrey0fX5Epc43L0uwDKmN2jK9vhc2ihCwXC1pmu8d2m/8wfTiXRJKGti55yw==
Expand Down

0 comments on commit e7f5255

Please sign in to comment.