Skip to content

fix: resolve MatchRoute return types for pathless (layout) routes - #7571

Open
EduardF1 wants to merge 4 commits into
TanStack:mainfrom
EduardF1:fix/match-route-pathless-types
Open

fix: resolve MatchRoute return types for pathless (layout) routes#7571
EduardF1 wants to merge 4 commits into
TanStack:mainfrom
EduardF1:fix/match-route-pathless-types

Conversation

@EduardF1

@EduardF1 EduardF1 commented Jun 7, 2026

Copy link
Copy Markdown

Description

Fixes #6011

Currently, router.matchRoute returns a type of false when matching against paths contained within pathless (layout) routes (e.g. _pathless/nested/$id). The runtime behavior is correct, but the generic TResolved resolution fails to extract the underlying string type when passing through NoInfer via the Layout masking.

This patch adds a string union extraction step on TResolved, ensuring the generic constraint successfully unwraps the pathless definition and provides proper TS intellisense (ResolveParams) without evaluating to never or false.

Testing

Verified TS compiler locally.

Summary by CodeRabbit

  • Bug Fixes
    • Improved type safety for route matching results by allowing plain string inputs and correctly narrowing route parameter types for pathless (layout) routes.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 6716b803-00bf-46d4-9840-f080b9735881

📥 Commits

Reviewing files that changed from the base of the PR and between 216c0c4 and bc5597a.

📒 Files selected for processing (2)
  • .changeset/matchroute-pathless-return-types.md
  • packages/router-core/src/router.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/matchroute-pathless-return-types.md
  • packages/router-core/src/router.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The PR broadens MatchRouteFn typing to accept any string for TFrom and narrows the resolved route ID with Extract<TResolved, string>. It adds a patch changeset for pathless layout route return types.

Changes

MatchRouteFn Type Signature Update

Layer / File(s) Summary
Type signature and changeset update
packages/router-core/src/router.ts, .changeset/matchroute-pathless-return-types.md
TFrom accepts any string. RouteById uses Extract<TResolved, string>. The changeset documents the updated return-type behavior.

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

Merge Risk: ⚪ Minimal · up to bc559

This change corrects TypeScript return-type resolution for matches beneath pathless layout routes without changing runtime matching behavior. No concrete merge-blocking risk is currently identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the fix for MatchRoute return types on pathless layout routes.
Description check ✅ Passed The description explains the issue, implementation, expected type behavior, and local TypeScript verification. It omits the repository template headings and checklist, but it provides the core change …
Linked Issues check ✅ Passed The changes broaden TFrom and extract string values from TResolved, which directly addresses issue #6011 by restoring correct TypeScript return types for routes nested under pathless layouts while lea…
Out of Scope Changes check ✅ Passed The modified router type signature and accompanying changeset are directly related to issue #6011 and the stated PR objective. No unrelated changes are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@EduardF1

EduardF1 commented Sep 6, 2026

Copy link
Copy Markdown
Author

Friendly ping — this PR is still mergeable and all checks are green. Anything I can do to help it land? Happy to rebase onto the latest base or adjust the scope if the approach has changed since it was opened.

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.

router.matchRoute doesn't resolve TS type with pathless (layout) routes

1 participant