router.matchRoute doesn't resolve TS type with pathless (layout) routes
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 143
Description
Which project does this relate to?
Router
Describe the bug
When trying to use the router.matchRoute function with a path that is contained within a pathless route, the resulting match result is typed to false. Running the function returns the correct value. It's only TS issue.
Your Example Website or App
https://stackblitz.com/edit/github-trezcbpr?file=src%2Fmain.tsx
Steps to Reproduce the Bug or Issue
- Create route
routes/_pathless/route.tsx - Create nested route
routes/_pathless/nested/$id.tsx - Call
router.matchRoute(use global router instance) with"/nested/$id.tsx"
// match has type 'false'
const match = router.matchRoute({
to: '/nested/$id',
params: {
id: 'someId',
},
});
return match && match.id; // Property 'id' does not exist on type 'never'.(2339)
Expected behavior
return type is false | ResolveParams<"/_pathless/nested/$id"> instead of false
Screenshots or Videos
Platform
- Router Version: 1.139.12
- OS: macOS
- Browser: Chrome
- Browser Version: 142.0.7444.176
- Bundler: vite
- Bundler Version: 7.1.7
Additional context
Maybe the same reason as at https://github.com/TanStack/router/issues/1680
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the router.matchRoute entry point and reproduce the issue using the linked StackBlitz example, focusing on the TypeScript type returned for a path under a pathless route. Done means the example infers false | ResolveParams<"/_pathless/nested/$id"> while preserving the correct runtime match behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100