Skip to content

fix(router-core): type route.children as the array stored at runtime - #8988

Open
shivamlaur022 wants to merge 1 commit into
TanStack:mainfrom
shivamlaur022:fix/4766-route-children-type
Open

shivamlaur022 wants to merge 1 commit into
TanStack:mainfrom
shivamlaur022:fix/4766-route-children-type

Conversation

@shivamlaur022

@shivamlaur022 shivamlaur022 commented Nov 24, 2026 •

Copy link
Copy Markdown

🎯 Changes

Fixes #4766.

addChildren / _addFileChildren store Object.values(children) when given an object (as the generated route tree does), but route.children was typed as the object. So routeTree.children autocompleted route names and .map didn't type-check.

children is now ResolveRouteChildren<TChildren>: an array of the values for object children, the same tuple for array children. types.children still keeps the object, so inference (and the perf win from #1564) is unchanged.

const tree = rootRoute.addChildren({ indexRoute, aboutRoute })
tree.children // before: { indexRoute: ...; aboutRoute: ... } | undefined
              // after:  Array<typeof indexRoute | typeof aboutRoute> | undefined

Added a type test in react-router/tests/route.test-d.tsx (fails on main, passes here). test:types passes on TS 5.6–7.0 for router-core and react-router.

Prepared with AI assistance (Claude Code), reviewed and tested by me.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Improved TypeScript types for route children supplied as objects, so they are represented as an array of child routes.
  • Improvements
    • Preserved readonly tuple types when route children are supplied as arrays, providing more accurate type information across both input formats.

`addChildren` and `_addFileChildren` accept children as an object (the
generated route tree passes one) but store `Object.values(children)`.
`route.children` was typed as the object, so `routeTree.children` offered
the child route names instead of array methods. Type it as an array of
the object's values; `types.children` keeps the object for inference.

Fixes TanStack#4766

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 76c0424

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@tanstack/router-core Patch
@tanstack/react-router Patch
@tanstack/react-start-client Patch
@tanstack/react-start-rsc Patch
@tanstack/react-start-server Patch
@tanstack/router-generator Patch
@tanstack/router-plugin Patch
@tanstack/solid-router Patch
@tanstack/solid-start-client Patch
@tanstack/solid-start-server Patch
@tanstack/start-client-core Patch
@tanstack/start-plugin-core Patch
@tanstack/start-server-core Patch
@tanstack/start-storage-context Patch
@tanstack/vue-router Patch
@tanstack/vue-start-client Patch
@tanstack/vue-start-server Patch
@tanstack/react-start Patch
@tanstack/router-cli Patch
@tanstack/router-vite-plugin Patch
@tanstack/solid-start Patch
@tanstack/start-static-server-functions Patch
@tanstack/vue-start Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change resolves object-shaped route children to an array type in route declarations and file-child handling. Type tests cover object and array inputs, and a patch changeset records the update.

Changes: Route children typing

Layer / File(s) Summary
Resolve and expose route children types
packages/router-core/src/route.ts, packages/react-router/tests/route.test-d.tsx, .changeset/route-children-array-type.md
ResolveRouteChildren<TChildren> maps object-shaped child maps to arrays and preserves array types. Route.children and BaseRoute.children use the resolved type. Type tests cover object inputs through addChildren and _addFileChildren, plus readonly tuple preservation for array inputs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: schiller-manuel

Merge Risk: Minimal · up to 76c04

This change fixes the TypeScript type of route.children so it matches the runtime array and supports array methods such as .map. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the router-core change: route.children is now typed as the array that is stored at runtime. The changeset summary, the route.ts type change, and the new type test all match this. The t…
Description check Passed The description covers the change and its motivation. It links issue #4766, shows a before and after example, and names the added type test. The checklist is filled in and the release impact is marked…
Linked Issues check Passed [#4766] requires routeTree.children to have a type that matches its runtime value, an array, so that code can iterate over root routes. The PR changes children on the Route interface and the `Ba…
Out of Scope Changes check Passed All changed files relate to the linked issue. packages/router-core/src/route.ts contains the new ResolveRouteChildren type, the updated children property types, and the casts in `_addFileChildre…
Full details: Title check

Explanation

The title names the router-core change: route.children is now typed as the array that is stored at runtime. The changeset summary, the route.ts type change, and the new type test all match this. The title is specific and follows the fix(scope) convention.

Full details: Description check

Explanation

The description covers the change and its motivation. It links issue #4766, shows a before and after example, and names the added type test. The checklist is filled in and the release impact is marked with a changeset. It follows the template, and the AI-authorship disclosure is present. It does not restate the template's HTML comment guidance, which is not required content.

Full details: Linked Issues check

Explanation

[#4766] requires routeTree.children to have a type that matches its runtime value, an array, so that code can iterate over root routes. The PR changes children on the Route interface and the BaseRoute class in packages/router-core/src/route.ts to ResolveRouteChildren&lt;TChildren&gt;. Per the PR summary, this type maps object children to an array of their value types and keeps array children as their tuple type. This matches the Object.values(children) result stored by addChildren and _addFileChildren, so .map and route-name autocompletion no longer conflict. types.children keeps the object shape, so inference is unchanged. A type test in packages/react-router/tests/route.test-d.tsx covers the object-to-array mapping and the array tuple case. No unmet coding requirement appears in the issue. Scope: the summary does not show the full resolved type body, so the exact union for object children was taken from the summary and not re-read from the source.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the linked issue. packages/router-core/src/route.ts contains the new ResolveRouteChildren type, the updated children property types, and the casts in _addFileChildren that match the runtime array. packages/react-router/tests/route.test-d.tsx adds the type test for this behavior. .changeset/route-children-array-type.md adds a patch changeset for the published @tanstack/router-core change, which the PR description requires for published code. No unrelated changes appear in the summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 61d5cdd and 76c0424.

Files selected for processing: 3

  • .changeset/route-children-array-type.md
  • packages/react-router/tests/route.test-d.tsx
  • packages/router-core/src/route.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect type on routeTree.children

1 participant