Update from 1.48.4 to 1.51.2 broke typesafe route prop
Hey everyone!
I have a context provider that takes some props for config, one of which I want to enforce to be a valid, existing route in my
routeTree
. Here's how I accomplished that before this upgrade:
After upgrading to v1.51.2, value.closeTo
in <WizardContext.Provider>
has a type error which reads:
If I change the type param passed into WizardProvider
it's reflected in the error, i.e. export default function WizardProvider<TTo extends string = "/">(props: {
shows the same errors with "not assignable to type '"/" | undefined'," but I'm not familiar enough with how the router is typed to understand how to fix this on my own!
TLDR; I would like to be able to define a <WizardProvider closeTo="/success">
and enforce that /success
is a route that exists in the routeTree
Would love some guidance. Thank you for your help!12 Replies
passive-yellow•13mo ago
if it's just "enforce that /success is a route that exists in the routeTree" then you can use
metropolitan-bronzeOP•13mo ago
Oh shoot! And then my
WizardContextValue
could set closeTo: ValidPaths;
?!
Testing now, that's so much cleanerpassive-yellow•13mo ago
yes
but this ofcourse only works for routes that neither have search nor path params
if you need that ... you are kinda creating a custom link component
which you can using
createLink
metropolitan-bronzeOP•13mo ago
Okay I will look into that too
passive-yellow•13mo ago
if you don't have params, don't bother
the above solution will then be the simplest one
metropolitan-bronzeOP•13mo ago
I think for current purposes we haven't run into an instance where we need to close one of our wizards to a path with params, but I wouldn't be surprised if we end up in that situation in the future
passive-yellow•13mo ago
out of curiosity: what kind of app are you building?
metropolitan-bronzeOP•13mo ago
I'm in the docs now and haven't been able to find a reference to createLink, where can I find more info about that?
passive-yellow•13mo ago
i still need to document this
it was experimental for a while
thus undocumented
you could have a look at this thread for now: https://discord.com/channels/719702312431386674/1267916028462235688
just so you get an idea how it is used
createLink
also misses some type safety when it comes to custom component props, also working on that
so might not be ready for primetimemetropolitan-bronzeOP•13mo ago
We're building a financial services app, one use case for this wizard model is KYC/KYB flows, where we use a route change to open a fullscreen dialog essentially to process ID verification; if a user abandons early I route them to a different place than if they finish the flow
passive-yellow•13mo ago
cool!
will this be publicly available?
metropolitan-bronzeOP•13mo ago
Yes! We're the New Money Company of San Fancisco (newmoneycompany.com), we were in YC's W24 batch
Mostly focused on platform partnerships at the moment for paying international contractors, but we did (and will again) have more individual-targeted services as well!
I think I'm unblocked for now, but I'll read that other thread and keep an eye out for createLink docs in the future! Thanks so much for your help