Skip to content

Compatibility with exactOptionalPropertyTypes: true #14734

@lensbart

Description

@lensbart

Reproduction

The route types generated by react-router typegen do not seem to type-check when tsconfig.json has "exactOptionalPropertyTypes": true.

I remember having this setting enabled a couple of months ago, without issue; but cannot reproduce a valid setup with any 7.x.0 version (I tried them all).

The type errors are on two types:

// .react-router/types/src/+types/root.ts
type Info = GetInfo<{
  file: "root.tsx", // this is just an example, the same type error is present in every file in `.react-router/`
  module: Module
}>
Type '{ file: "root.tsx"; module: typeof import("/some-local-path/src/root"); }' does not satisfy the constraint '{ file: keyof RouteFiles; module: RouteModule$1; }'.
  The types of 'module.action' are incompatible between these types.
    Type '(({ params, request, ...restArgs }: CreateServerActionArgs<Info & { module: typeof import("/some-local-path/src/root"); matches: Matches; }>) => Promise<...>) | undefined' is not assignable to type 'Func'.
      Type 'undefined' is not assignable to type 'Func'.ts(2344)

and:

// .react-router/types/src/+types/root.ts
type Annotations = GetAnnotations<Info & { module: Module, matches: Matches }, false>;
Type 'Info & { module: typeof import("/some-local-path/src/root"); matches: Matches; }' does not satisfy the constraint 'RouteInfo'.
  Type 'Info & { module: typeof import("/some-local-path/src/root"); matches: Matches; }' is not assignable to type '{ module: RouteModule$1; matches: MatchInfo[]; }'.
    The types of 'module.action' are incompatible between these types.
      Type '(({ params, request, ...restArgs }: CreateServerActionArgs<Info & { module: typeof import("/some-local-path/src/root"); matches: Matches; }>) => Promise<...>) | undefined' is not assignable to type 'Func'.
        Type 'undefined' is not assignable to type 'Func'.ts(2344)

System Info

System:
    OS: macOS 26.2
    CPU: (16) arm64 Apple M3 Max
    Memory: 1.77 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.9.0 - ~/.nvm/versions/node/v24.9.0/bin/node
    npm: 11.7.0 - ~/.nvm/versions/node/v24.9.0/bin/npm
  Browsers:
    Chrome: 144.0.7559.59
    Edge: 113.0.1774.35
    Firefox: 131.0.2
    Safari: 26.2
@react-router/dev: 7.12.0
@react-router/node: 7.12.0
@react-router/serve: 7.12.0
react-router: 7.12.0

Used Package Manager

npm

Expected Behavior

No type error

Actual Behavior

Two type errors per file in .react-router/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions