Skip to content

typegen generates invalid TypeScript (empty page type) for pathless layout routes using remix-flat-routes #14783

@iulspop

Description

@iulspop

Reproduction

Minimal reproduction repo: https://github.com/iulspop/react-router-typegen-bug-repro

Steps to reproduce:

git clone https://github.com/iulspop/react-router-typegen-bug-repro
cd react-router-typegen-bug-repro
pnpm install
pnpm typecheck

The typecheck fails with:

.react-router/types/+routes.ts(36,11): error TS1110: Type expected.

Route structure:

app/routes/
  _index.tsx
  _parent+/
    _parent-layout.tsx       # pathless layout — only has nested layout children
    _child-layout.tsx        # nested pathless layout
    _child-layout+/
      page-a.tsx             # /page-a
      page-b.tsx             # /page-b

routes.ts:

import { remixRoutesOptionAdapter } from "@react-router/remix-routes-option-adapter";
import { flatRoutes } from "remix-flat-routes";

export default remixRoutesOptionAdapter((defineRoutes) => {
  return flatRoutes("routes", defineRoutes);
});

Running react-router typegen produces invalid TypeScript for _parent-layout:

"routes/_parent+/_parent-layout.tsx": {
    id: "routes/_parent+/_parent-layout";
    page: ;  // <-- TS1110: Type expected
};

The bug occurs when a pathless layout route's children are all nested layouts (no direct leaf routes). Other pathless layouts with at least one direct leaf child generate correctly.

System Info

System:
  OS: macOS 26.2
  CPU: (14) arm64 Apple M4 Pro
  Memory: 5.09 GB / 48.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 22.17.0 - /Users/iulspop/.nvm/versions/node/v22.17.0/bin/node
  npm: 10.9.2 - /Users/iulspop/.nvm/versions/node/v22.17.0/bin/npm
  pnpm: 10.28.2 - /Users/iulspop/.nvm/versions/node/v22.17.0/bin/pnpm
Browsers:
  Chrome: 144.0.7559.133
  Firefox: 147.0.2
  Safari: 26.2
npmPackages:
  @react-router/dev: 7.13.0 => 7.13.0
  @react-router/node: 7.13.0 => 7.13.0
  @react-router/remix-routes-option-adapter: 7.13.0 => 7.13.0
  @react-router/serve: 7.13.0 => 7.13.0
  react-router: 7.13.0 => 7.13.0
  vite: 7.3.1 => 7.3.1

Used Package Manager

pnpm

Expected Behavior

The page type for the pathless layout should be a union of all descendant pages:

page: "/page-a" | "/page-b";

Or never if no pages are directly reachable.

Actual Behavior

The typegen emits invalid TypeScript with an empty page type:

page: ;

This causes TS1110: Type expected and breaks tsc.

Workaround: Patch the output after typegen:

{
  "scripts": {
    "typegen:router": "react-router typegen && sed -i '' 's/page: ;/page: never;/g' .react-router/types/+routes.ts"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions