TanStack / TanStack/router

[Typesafe routing] Uncatched typescript error

Open
#5,466 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

types
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

I expect TS to catch an invalid navigation construct. When doing some dynamic routing, if I inject a union type as to param, in certain situation TS seems to ignore invalid routes.

In the example, you'll see that using absolute path raise the error, while relative one is silently ignored.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-vh8dm4rb?file=src%2Froutes%2Findex.tsx

Steps to Reproduce the Bug or Issue
  1. Open the repro
  2. See the TS error in action
Expected behavior

Ideally, the TS error should be consistent while using absolute/relative routing.

Screenshots or Videos

No response

Platform
  • Router / Start Version: [e.g. 1.121.0]
  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Browser Version: [e.g. 91.1]
  • Bundler: [e.g. vite]
  • Bundler Version: [e.g. 7.0.0]
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the StackBlitz reproduction at src/routes/index.tsx and compare the absolute and relative navigation cases using a union type for the to parameter. Trace the router's TypeScript route validation to determine why the relative case accepts an invalid route; done means both forms report the expected type error.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.