TanStack / router

🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering.
https://tanstack.com/router
MIT License
8.26k stars 656 forks source link

`to` allows the `string` type #2623

Open nstepien opened 1 month ago

nstepien commented 1 month ago

Which project does this relate to?

Router

Describe the bug

As the title says, to accepts the string type, meaning that these examples will be "valid":

router.navigate({ to: `/posts?filter=${filter}` });

<Link to={`/posts?filter=${filter}`} />

Your Example Website or App

https://stackblitz.com/edit/github-vg75qp?file=src%2Fmain.tsx

Steps to Reproduce the Bug or Issue

  1. Pass a value of type string to to

Expected behavior

The string type should not be accepted by to's type

Screenshots or Videos

No response

Platform

Additional context

I don't know if this is intentional, but it's making migrating away from another router more difficult as we can't automatically trust links/navigations.

schiller-manuel commented 1 month ago

we have been thinking about this. thanks for opening this issue to remind us :)

swbtrifork commented 4 weeks ago

My workaround for now seems to be to narrow the type manually by using as const satisfies LinkProps["to"];, but this was also an issue for me, especially in shared components.