Skip to content

Commit e7f5255

Browse files
authored
ref(react-router): Make RouteProps typing more generic (#3570)
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.
1 parent c3b1bb5 commit e7f5255

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

packages/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"@types/hoist-non-react-statics": "^3.3.1",
3636
"@types/react": "^17.0.3",
3737
"@types/react-router-3": "npm:@types/[email protected]",
38-
"@types/react-router-4": "npm:@types/[email protected].13",
39-
"@types/react-router-5": "npm:@types/[email protected].13",
38+
"@types/react-router-4": "npm:@types/[email protected].14",
39+
"@types/react-router-5": "npm:@types/[email protected].14",
4040
"eslint": "7.6.0",
4141
"eslint-plugin-react": "^7.20.5",
4242
"eslint-plugin-react-hooks": "^4.0.8",

packages/react/src/reactrouter.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@ export type RouteConfig = {
2323
routes?: RouteConfig[];
2424
};
2525

26-
interface RouteProps {
27-
[propName: string]: any;
28-
location?: Location;
29-
component?: React.ComponentType<any> | React.ComponentType<any>;
30-
render?: (props: any) => React.ReactNode;
31-
children?: ((props: any) => React.ReactNode) | React.ReactNode;
32-
path?: string | string[];
33-
exact?: boolean;
34-
sensitive?: boolean;
35-
strict?: boolean;
36-
}
37-
3826
type MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null;
3927
/* eslint-enable @typescript-eslint/no-explicit-any */
4028

@@ -148,9 +136,7 @@ function computeRootMatch(pathname: string): Match {
148136
}
149137

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

156142
const WrappedRoute: React.FC<P> = (props: P) => {

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,10 +3300,10 @@
33003300
"@types/history" "^3"
33013301
"@types/react" "*"
33023302

3303-
"@types/react-router-4@npm:@types/[email protected].13", "@types/react-router-5@npm:@types/[email protected].13":
3304-
version "5.1.13"
3305-
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-5.1.13.tgz#051c0d229bd48ad90558a1db500708127cc512f7"
3306-
integrity sha512-ZIuaO9Yrln54X6elg8q2Ivp6iK6p4syPsefEYAhRDAoqNh48C8VYUmB9RkXjKSQAJSJV0mbIFCX7I4vZDcHrjg==
3303+
"@types/react-router-4@npm:@types/[email protected].14", "@types/react-router-5@npm:@types/[email protected].14":
3304+
version "5.1.14"
3305+
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-5.1.14.tgz#e0442f4eb4c446541ad7435d44a97f8fe6df40da"
3306+
integrity sha512-LAJpqYUaCTMT2anZheoidiIymt8MuX286zoVFPM3DVb23aQBH0mAkFvzpd4LKqiolV8bBtZWT5Qp7hClCNDENw==
33073307
dependencies:
33083308
"@types/history" "*"
33093309
"@types/react" "*"
@@ -14454,7 +14454,7 @@ neo-async@^2.5.0, neo-async@^2.6.0, neo-async@^2.6.1, neo-async@^2.6.2:
1445414454
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
1445514455
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==
1445614456

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

0 commit comments

Comments
 (0)