#Handling types of "prev" value

1 messages · Page 1 of 1 (latest)

midnight owl
#

I have a link in my code that looks like this:

<Link
  to="/organization/$organizationSlug/"
  params={(prev) => ({
    organizationSlug: prev.organizationSlug
  })}
>

At this point in my code I am 100% sure that organizaionSlug is valid and defined, since I handle that validation in beforeLoad, in the router.
But prev.organizaionSlug is not a valid input for my params, and I get this type error:

Property 'organizationSlug' does not exist on type '{} | {} | ({} & { organizationSlug: string; }) .......
Property 'organizationSlug' does not exist on type '{}'

I am able to get the error to disappear by doing this:

<Link
  to="/organization/$organizationSlug/"
  params={(prev) => {
    const prevTyped = prev as { organizationSlug?: string };
    return {
      organizationSlug: prevTyped.organizationSlug!,
    };
  }}
>

But that solution is very ugly, and it feels really wrong.
How do I handle this in a better way?

manic grove
#

you must set the from property

#

then all is handled automatically

#

in fact, if your from already has the path param, you don't need to specify it anymore