Open EliasWatson opened 3 months ago
it works if you omit the return type declaration QueryPersister<TData, any>
:
I think it's related to "Intra expression inference" maybe ? TypeScript does inference differently if function parameters are used. Could be related to:
You can see that if you hover queryOptions
where it errors, it's actually inferred as queryOptions<unknown, Error, unknown, string[]>
. So data
is of type unknown
instead of string
, which I think is because it can't be inferred from the queryFn
for "reasons" 🤷
Describe the bug
When using
experimental_createPersister
from@tanstack/query-persist-client-core
, TypeScript throws a type error inqueryOptions()
whenqueryFn
has an argument, but doesn't throw a type error ifqueryFn
has no arguments. The type error goes away if we define the generic argument onqueryOptions()
.Your minimal, reproducible example
https://codesandbox.io/p/github/EliasWatson/tanstack-query-persist-bug-example/main?import=true
Steps to reproduce
QueryPersister
usingexperimental_createPersister
.queryFn
that has no arguments. Notice that there are no TypeScript errors.queryFn
. Notice that TypeScript now throws an error.23 persister: createPersister(),
node_modules/@tanstack/query-core/build/modern/hydration-DtrabBHC.d.ts:577:5 577 persister?: QueryPersister<NoInfer, NoInfer, NoInfer>;