Skip to content

[Bug]: type errors with exactOptionalPropertyTypes #11991

@marekdedic

Description

@marekdedic

What version of React Router are you using?

6.26.2

Steps to Reproduce

  1. Install react-router
  2. Enable exactOptionalPropertyTypes in your tsconfig
  3. Compile

Expected Behavior

No errors

Actual Behavior

node_modules/react-router/dist/index.d.ts:17:116 - error TS2344: Type 'RouteMatch<string, RouteObject>' does not satisfy the constraint 'AgnosticRouteMatch<string, AgnosticRouteObject>'.
  Types of property 'route' are incompatible.
    Type 'RouteObject' is not assignable to type 'AgnosticRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.

17 export interface unstable_PatchRoutesOnNavigationFunction extends unstable_AgnosticPatchRoutesOnNavigationFunction<RouteMatch> {
                                                                                                                      ~~~~~~~~~~

node_modules/react-router/dist/lib/components.d.ts:60:30 - error TS2344: Type 'NonIndexRouteObject' does not satisfy the constraint 'AgnosticRouteObject'.
  Type 'NonIndexRouteObject' is not assignable to type 'AgnosticNonIndexRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
    Type 'NonIndexRouteObject' is not assignable to type 'AgnosticBaseRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
      Types of property 'caseSensitive' are incompatible.
        Type 'boolean | undefined' is not assignable to type 'boolean'.

60     lazy?: LazyRouteFunction<NonIndexRouteObject>;
                                ~~~~~~~~~~~~~~~~~~~

node_modules/react-router/dist/lib/components.d.ts:81:30 - error TS2344: Type 'IndexRouteObject' does not satisfy the constraint 'AgnosticRouteObject'.

81     lazy?: LazyRouteFunction<IndexRouteObject>;
                                ~~~~~~~~~~~~~~~~

node_modules/react-router/dist/lib/context.d.ts:20:30 - error TS2344: Type 'RouteObject' does not satisfy the constraint 'AgnosticRouteObject'.
  Type 'IndexRouteObject' is not assignable to type 'AgnosticRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
    Type 'IndexRouteObject' is not assignable to type 'AgnosticIndexRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
      Type 'IndexRouteObject' is not assignable to type 'AgnosticBaseRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
        Types of property 'caseSensitive' are incompatible.
          Type 'boolean | undefined' is not assignable to type 'boolean'.
            Type 'undefined' is not assignable to type 'boolean'.

20     lazy?: LazyRouteFunction<RouteObject>;
                                ~~~~~~~~~~~

node_modules/react-router/dist/lib/context.d.ts:39:30 - error TS2344: Type 'RouteObject' does not satisfy the constraint 'AgnosticRouteObject'.

39     lazy?: LazyRouteFunction<RouteObject>;
                                ~~~~~~~~~~~

node_modules/react-router/dist/lib/context.d.ts:46:151 - error TS2344: Type 'RouteObjectType' does not satisfy the constraint 'AgnosticRouteObject'.
  Type 'RouteObject' is not assignable to type 'AgnosticRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
    Type 'RouteObjectType' is not assignable to type 'AgnosticNonIndexRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
      Type 'RouteObject' is not assignable to type 'AgnosticNonIndexRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
        Type 'IndexRouteObject' is not assignable to type 'AgnosticNonIndexRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
          Type 'IndexRouteObject' is not assignable to type 'AgnosticBaseRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
            Type 'RouteObjectType' is not assignable to type 'AgnosticBaseRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
              Type 'RouteObject' is not assignable to type 'AgnosticBaseRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
                Type 'IndexRouteObject' is not assignable to type 'AgnosticBaseRouteObject' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.

46 export interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
                                                                                                                                                         ~~~~~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions