You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
URL-Params are kept even if not provided requiring TypeScript error when having exactOptionalPropertyTypes enabled #5582
Since required parameters are also required on the params-prop of the Link component, I would expect those not being present to be removed.
In the stackblitz example, I defined a route as /users/{-$id} and added some links to it:
Menu - without params prop.
Link "User1" - having params prop setting id to 1.
Link "User2" - having params prop setting id to 2.
Link "List (not working 😬)" - having params prop with an empty object.
Link "List (working 🤩)" - having params prop setting id to undefined.
The last option is invalid when having exactOptionalPropertyTypes enabled in your TypeScript config.
When imagining a different scenario, where I have multiple variables, some of them required, I can actually (against the types) leave out parameters already provided by the former route. In my real-world scenario I try to build a link to and from /company/$companyId/users/{-$userId}. Based on the types I have to provide companyId, but based on the implementation, I don't have to, but I should set userId to undefined if I want to remove it, which creates a TypeScript error, because I have exactOptionalPropertyTypes enabled.
Putting this in another perspective: This is a very powerful concept most programmers (at least all of our team here) aren't really used to, so I think it would be good to spend some more lines on this, somewhere as central as the Routing Concepts page. Yes, Everything is Relative, but I think this concept isn't as clearly communicated as I would need it to understand it fully while reading the docs.
@schiller-manuel, I tried to reach you through discord, but didn't have any luck - trying it here again:
I went through the docs and got the impression that docs are already quite comprehensive - I think I'm just missing a few more examples here and there.
Another example using functional style, where I skip what I get as parameters of the previous route, where one might be even more sure the id wouldn't be taken over:
This link will work in all cases, except if I'm on a route that already has the id prop. This way, I have to be quite knowledgeable about the place I am. This might have worked prior to the introduction of optional parameters, because TypeScript requires me to set the companyId (I could also have that left out and it would work, despite TypeScript complaining).
I don't know what a good solution here could be, but one thought was to make all keys of a route required in the params. This might break with existing definitions, but would at least make clear what value should be set, in the case that a user doesn't provide a from. IF he provides a from, we can expect that he knows what he's doing.
Activity
fix: make optional path params explicitly undefined for use with `exa…
schiller-manuel commentedon Oct 23, 2025
they are now typed explicitly as
| undefinedSimonSimCity commentedon Oct 28, 2025
@schiller-manuel, thanks for the quick response and update!
In addition to this change, I would propose to add an additional note to https://tanstack.com/router/latest/docs/framework/react/guide/path-params#navigating-with-optional-parameters mentioning, that parameters (also optional ones) which are not defined, are taken from the
fromroute. In this regard, you are defining what should change.Imagine a link as following:
Example: https://stackblitz.com/edit/github-abbyhecx-5shqc1bs?file=src%2Froutes%2F{%24companyId}%2Fuser%2F{-%24id}.tsx
I just see this as such a common pitfall, that I think it's worth mentioning the concept over and over again, also at this place.
I was trying to find this somewhere, but couldn't see it being mentioned in https://tanstack.com/router/latest/docs/framework/react/routing/routing-concepts, but only as a small note in https://tanstack.com/router/latest/docs/framework/react/guide/navigation#navigating-with-optional-parameters.
Putting this in another perspective: This is a very powerful concept most programmers (at least all of our team here) aren't really used to, so I think it would be good to spend some more lines on this, somewhere as central as the Routing Concepts page. Yes, Everything is Relative, but I think this concept isn't as clearly communicated as I would need it to understand it fully while reading the docs.
schiller-manuel commentedon Oct 28, 2025
absolutely, docs should reflect this. want to give it a go and create a PR for the docs?
SimonSimCity commentedon Nov 6, 2025
@schiller-manuel, I tried to reach you through discord, but didn't have any luck - trying it here again:
I went through the docs and got the impression that docs are already quite comprehensive - I think I'm just missing a few more examples here and there.
I found the following guidelines - although maybe too inconspicuous:
from(safest to useRoute.fullPath).fromand TypeScript will guide you.I think that - equiped with these two guidelines - I can build something that's safe, except this case:
Imagine, I don't know the route (it's a shared component), and I want to create a link:
Another example using functional style, where I skip what I get as parameters of the previous route, where one might be even more sure the
idwouldn't be taken over:This link will work in all cases, except if I'm on a route that already has the
idprop. This way, I have to be quite knowledgeable about the place I am. This might have worked prior to the introduction of optional parameters, because TypeScript requires me to set thecompanyId(I could also have that left out and it would work, despite TypeScript complaining).I don't know what a good solution here could be, but one thought was to make all keys of a route required in the params. This might break with existing definitions, but would at least make clear what value should be set, in the case that a user doesn't provide a
from. IF he provides a from, we can expect that he knows what he's doing.