Skip to content

matchRoutes type is incompatible with routes parameter in react-router integration #5959

Closed
@rafael-zilberman

Description

@rafael-zilberman

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/react

SDK Version

7.15.0

Framework Version

17.0.2

Link to Sentry event

No response

Steps to Reproduce

Following the react-router integration documentation here:
https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/

Using the following code:

import {
    createRoutesFromChildren,
    matchRoutes,
    useLocation,
    useNavigationType
} from "react-router-dom";

Sentry.init({
    dsn: process.env.REACT_APP_SENTRY_DSN,
    integrations: [new BrowserTracing({
        routingInstrumentation: Sentry.reactRouterV6Instrumentation(
            useEffect,
            useLocation,
            useNavigationType,
            createRoutesFromChildren,
            matchRoutes,
        ),
    }), new ExtraErrorDataIntegration(), new OfflineIntegration(), postHogIntegration],
    tracesSampleRate: 1.0,
});

Expected Result

No typescript error should be shown

Actual Result

Produces the following Typescript error:

TS2345: Argument of type '<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: string | Partial<Location>, basename?: string | undefined) => AgnosticRo
uteMatch<...>[] | null' is not assignable to parameter of type 'MatchRoutes'.
  Types of parameters 'routes' and 'routes' are incompatible.
    Type 'RouteObject[]' is not assignable to type 'AgnosticRouteObject[]'.
      Type 'RouteObject' is not assignable to type 'AgnosticRouteObject'.
        Type 'RouteObject' is not assignable to type 'AgnosticNonIndexRouteObject'.
          Type 'RouteObject' is not assignable to type '{ children?: AgnosticRouteObject[] | undefined; index?: false | undefined; }'.
            Types of property 'children' are incompatible.
              Type 'RouteObject[] | undefined' is not assignable to type 'AgnosticRouteObject[] | undefined'.
                Type 'RouteObject[]' is not assignable to type 'AgnosticRouteObject[]'.
                  Type 'RouteObject' is not assignable to type 'AgnosticRouteObject'.
                    Type 'RouteObject' is not assignable to type 'AgnosticNonIndexRouteObject'.
                      Types of property 'index' are incompatible.
                        Type 'boolean | undefined' is not assignable to type 'false | undefined'.
                          Type 'true' is not assignable to type 'false'.
    36 |                 useNavigationType,
    37 |                 createRoutesFromChildren,
  > 38 |                 matchRoutes,
       |                 ^^^^^^^^^^^
    39 |             ),
    40 |         }), new ExtraErrorDataIntegration(), new OfflineIntegration(), postHogIntegration],
    41 |         tracesSampleRate: 1.0,

Metadata

Metadata

Assignees

Labels

Package: reactIssues related to the Sentry React SDK

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions