TanStackT
TanStack2y ago
1 reply
near-sapphire

Validate Search different output and input types?

I used to have the following setup:

const route = {
  path: '/zzz'
  ...
  validateSearch: zzzSearchSchema
}

const zzzSearchSchema = z.object({
  foo: z.number().min(3)
}).catch({
  foo: 3
})

...

const FooBar= () => <Navigate to={'/zzz'} search={true} />


which makes sense to me, when I render FooBar i expect to navigate to '/zzz', with default params
This setup allowed me to keep all the defaults in a single place (the schema)
But after updating to the newest version this breaks
export type SearchParamOptions<
  TRouter extends AnyRouter,
  TFrom,
  TTo extends string,
> =
  IsRequired<TRouter, 'SEARCH', TFrom, TTo> extends never
    ? MakeOptionalSearchParams<TRouter, TFrom, TTo>
    : MakeRequiredSearchParams<TRouter, TFrom, TTo>


SearchParamOptions are now using MakeRequiredSearchParams, which disallows true

How can I have my strongly typed search params inside of my component, while having freedom to pass in any input into them?
Was this page helpful?