-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Labels
Description
Describe the bug
In vue-query if initialData
function returns undefined typescript error is displayed.
According to the docs this should be allowed https://tanstack.com/query/latest/docs/framework/react/guides/initial-query-data#conditional-initial-data-from-cache and query should fetch from hard loading state instead.
Your minimal, reproducible example
Steps to reproduce
- Go to minimal repro typescript playground
- See type error for
initialData
No overload matches this call.
Overload 1 of 2, '(options: UndefinedInitialQueryOptions<Config, Error, Config, readonly ["config"]>): UndefinedInitialQueryOptions<Config, Error, Config, readonly [...]> & { ...; }', gave the following error.
Type '() => Config | undefined' is not assignable to type 'undefined'.
Overload 2 of 2, '(options: DefinedInitialQueryOptions<Config, Error, Config, readonly ["config"]>): DefinedInitialQueryOptions<Config, Error, Config, readonly [...]> & { ...; }', gave the following error.
Type '() => Config | undefined' is not assignable to type 'Config | (() => Config) | (MaybeRefDeep<Config | InitialDataFunction<Config> | undefined> & (Config | (() => Config)))'.
Type '() => Config | undefined' is not assignable to type '() => Config'.
Type 'Config | undefined' is not assignable to type 'Config'.
Type 'undefined' is not assignable to type 'Config'.(2769)
hydration-BlEK5ylC.d.ts(606, 5): The expected type comes from property 'initialData' which is declared here on type 'UndefinedInitialQueryOptions<Config, Error, Config, readonly ["config"]>'
hydration-BlEK5ylC.d.ts(606, 5): The expected type comes from property 'initialData' which is declared here on type 'DefinedInitialQueryOptions<Config, Error, Config, readonly ["config"]>'
Expected behavior
initialData
allows to return undefined. No type errors produced.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
N/A
Tanstack Query adapter
vue-query
TanStack Query version
v5.74.6
TypeScript version
v5.8.3
Additional context
Query still fetches just fine from hard loading state so the logic is correct. Also no type errors in react-query
for the exact same code.