Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Typescript error in useFilter hook from Query Router Search Params example #5812

Open
tyschroed opened this issue Nov 20, 2024 · 1 comment

Comments

@tyschroed
Copy link

TanStack Table version

8.20.5

Framework/Library version

18.3.1

Describe the bug and the steps to reproduce it

In this example of using Tanstack Router search params via a useFilters hook, there are some type errors when patching the param values.

Type '(prev: { pageIndex?: number | undefined; id?: number | undefined; firstName?: string | undefined; lastName?: string | undefined; age?: number | undefined; pageSize?: number | undefined; sortBy?: `${string}.asc` | ... 1 more ... | undefined; foo?: string | undefined; bar?: number | undefined; }) => { ...; } & Partial...' is not assignable to type 'true | ParamsReducerFn<Router<RootRoute<undefined, {}, AnyContext, AnyContext, {}, undefined, RootRouteChildren, FileRouteTypes>, TrailingSlashOption, boolean, Record<...>, Record<...>>, "SEARCH", string, string | undefined> | undefined'.
  Type '(prev: { pageIndex?: number | undefined; id?: number | undefined; firstName?: string | undefined; lastName?: string | undefined; age?: number | undefined; pageSize?: number | undefined; sortBy?: `${string}.asc` | ... 1 more ... | undefined; foo?: string | undefined; bar?: number | undefined; }) => { ...; } & Partial...' is not assignable to type 'ParamsReducerFn<Router<RootRoute<undefined, {}, AnyContext, AnyContext, {}, undefined, RootRouteChildren, FileRouteTypes>, TrailingSlashOption, boolean, Record<...>, Record<...>>, "SEARCH", string, string | undefined>'.
    Type '{ pageIndex?: number | undefined; id?: number | undefined; firstName?: string | undefined; lastName?: string | undefined; age?: number | undefined; pageSize?: number | undefined; sortBy?: `${string}.asc` | ... 1 more ... | undefined; foo?: string | undefined; bar?: number | undefined; } & Partial<...>' is not assignable to type 'never'.(2322)
link.d.ts(62, 5): The expected type comes from property 'search' which is declared here on type 'NavigateOptions<Router<RootRoute<undefined, {}, AnyContext, AnyContext, {}, undefined, RootRouteChildren, FileRouteTypes>, TrailingSlashOption, boolean, Record<...>, Record<...>>, string, string | undefined, string, "">'
(property) MakeOptionalSearchParams<Router<RootRoute<undefined, {}, AnyContext, AnyContext, {}, undefined, RootRouteChildren, FileRouteTypes>, TrailingSlashOption, boolean, Record<...>, Record<...>>, string, string | undefined>.search?: true | ParamsReducerFn<Router<RootRoute<undefined, {}, AnyContext, AnyContext, {}, undefined, RootRouteChildren, FileRouteTypes>, TrailingSlashOption, boolean, Record<...>, Record<...>>, "SEARCH", string, string | undefined> | undefined```

### Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://stackblitz.com/github/tanstack/table/tree/main/examples/react/query-router-search-params?embed=1&theme=dark&preset=node&file=src/main.tsx

### Screenshots or Videos (Optional)

_No response_

### Do you intend to try to help solve this bug with your own PR?

No, because I do not know how

### Terms & Code of Conduct

- [x] I agree to follow this project's Code of Conduct
- [x] I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
@KevinVandy KevinVandy added v7 and removed v7 labels Nov 30, 2024
@amalkurbanbaev
Copy link

I solved this by specifying an empty string for the path to:

 const setFilters = (partialFilters: Partial<typeof filters>) =>
    navigate({
      to: "",
      search: (prev) => cleanEmptyParams({ ...prev, ...partialFilters }),
    });
  const resetFilters = () => navigate({ to: "", search: {} });

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants