Skip to content

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

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

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

Conversation

@EduardF1
Copy link
Copy Markdown

@EduardF1 EduardF1 commented Jun 7, 2026

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 parameter extraction in route matching operations, preventing incorrect type inference in certain scenarios.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2c3beba2-c48e-4b62-9852-5674a6c367d3

📥 Commits

Reviewing files that changed from the base of the PR and between 757d433 and 36e2fb6.

📒 Files selected for processing (1)
  • packages/router-core/src/router.ts

📝 Walkthrough

Walkthrough

The PR refines the MatchRouteFn type signature to fix type resolution issues with pathless layout routes. The TFrom generic constraint broadens to accept any string, and the return type uses Extract<TResolved, string> to ensure only string-typed resolutions flow into RouteById, correcting param type inference.

Changes

MatchRouteFn Type Signature Update

Layer / File(s) Summary
Type signature broadening and return-type extraction
packages/router-core/src/router.ts
TFrom generic constraint expands from only RoutePaths<TRouteTree> to RoutePaths<TRouteTree> | string to allow broader string types. Return type uses Extract<TResolved, string> on the RouteById generic argument to prevent non-string resolutions from affecting allParams type computation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit hops through TypeScript lands,
Broadening paths with gentle hands,
Extract makes types align,
Pathless routes now work divine! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: resolving MatchRoute return type issues for pathless (layout) routes, which directly corresponds to the core change in the PR.
Linked Issues check ✅ Passed The PR successfully addresses issue #6011 by modifying the MatchRouteFn type signature to extract string types from TResolved and broaden TFrom, fixing TypeScript typing for pathless route matching.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the MatchRouteFn type signature for pathless routes as specified in issue #6011; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

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