Strictly typed Link wrapper
I'd like to create a strictly typed
<Link> wrapper like the following example:
But this is unfortunately not strictly typed. TS will not understand that a certain to prop requires the corresponding params.
Has anyone got this to work? I've tried different link prop types: LinkOptions, LinkProps, LinkPropsOptions, NavigateOptions, ToOptions15 Replies
fascinating-indigo•2y ago
LinkProps works for me

rare-sapphireOP•2y ago
Interesting, are you using the latest version?
It seems broken in the basic example from the docs as well
rare-sapphireOP•2y ago

fascinating-indigo•2y ago
I'm on 1.1.4. But looking at your screenshot, that's what I have as well. All params are optional, so providing an empty object is fine. I believe that's because it reuses current params if possible. Could be a bug though, not sure of the intention
absent-sapphire•2y ago
you need to foward the generic type parameters like this:
rare-sapphireOP•2y ago
Thanks for the example!
rare-sapphireOP•2y ago
There seems to be a bug in the router, when pasting the
CustomLink in this example https://stackblitz.com/github/tanstack/router/tree/main/examples/react/kitchen-sink?embed=1&theme=dark there's a type error.StackBlitz
Router Kitchen Sink Example - StackBlitz
Run official live example code for Router Kitchen Sink, created by Tanstack on StackBlitz
rare-sapphireOP•2y ago
Same in my local environment
helpful-purple•2y ago
this is gold!
quickest-silver•2y ago
if anyone is getting strange typescript errors from this snippet, try upgrading to typescript 5.3.3 :)
helpful-purple•2y ago
Did anything changed inside this approach? It does not seem to give me typings any longer in most recent router update
harsh-harlequin•2y ago
this works fine for me
metropolitan-bronze•2y ago
I get the same ts error. did you find a solution?
wee-brown•14mo ago
Latest one I found from Sean: https://github.com/SeanCassiere/nv-rental-clone/blob/master/src/routes/-components/auth/header/app-navigation.tsx#L111C1-L131C3
GitHub
nv-rental-clone/src/routes/-components/auth/header/app-navigation.t...
Navotar with Tailwind and Tanstack Router and Query - SeanCassiere/nv-rental-clone
wee-brown•14mo ago
I changed it a bit so the API is the. same as the original: