TanStack/query · error
Bad argument type. Starting with v5, only the "Object" form
Error message
Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object
What it means
Dev-only runtime guard in Preact Query's `useBaseQuery`. In v5 the hooks accept exactly one `options` object; the v4 positional overloads (`useQuery(key, fn, options)`) were removed. If `options` is not a plain object, or is an array (e.g. a query key was passed directly), the hook throws before touching the observer. It only fires when `NODE_ENV !== 'production'`.
Source
Thrown at packages/preact-query/src/useBaseQuery.ts:46
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey extends QueryKey,
>(
options: UseBaseQueryOptions<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey
>,
Observer: typeof QueryObserver,
queryClient?: QueryClient,
): QueryObserverResult<TData, TError> {
if (process.env.NODE_ENV !== 'production') {
if (typeof options !== 'object' || Array.isArray(options)) {
throw new Error(
'Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',
)
}
}
const isRestoring = useIsRestoring()
const errorResetBoundary = useQueryErrorResetBoundary()
const client = useQueryClient(queryClient)
const defaultedOptions = client.defaultQueryOptions(options)
;(client.getDefaultOptions().queries as any)?._experimental_beforeQuery?.(
defaultedOptions,
)
if (process.env.NODE_ENV !== 'production') {
if (!defaultedOptions.queryFn) {
console.error(
`[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,View on GitHub (pinned to 159982c80b)
Solutions
- Convert the call to the single-object signature: `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })`.
- Run the v5 remove-overloads codemod against the affected files: `npx @tanstack/query-codemods remove-overloads --file src/...`.
- Search the codebase for `useQuery(`, `useInfiniteQuery(`, `useMutation(` and audit each to confirm it passes one object.
- If a custom wrapper forwards args, refactor it to accept and spread an options object.
Example fix
// before
const { data } = useQuery(['todos'], fetchTodos)
// after
const { data } = useQuery({ queryKey: ['todos'], queryFn: fetchTodos }) Defensive patterns
Strategy: type-guard
Validate before calling
function assertQueryOptionsObject(options: unknown) {
if (options === null || typeof options !== 'object' || Array.isArray(options)) {
throw new TypeError('useQuery expects a single options object in v5')
}
} Type guard
const isPlainOptionsObject = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object' && !Array.isArray(v)
Try / catch
// Wrap legacy call sites in a compatibility shim while migrating.
function safeUseQuery(arg: any, fn?: any, rest?: any) {
if (Array.isArray(arg)) return useQuery({ queryKey: arg, queryFn: fn, ...(rest || {}) })
if (typeof arg === 'string') return useQuery({ queryKey: [arg], queryFn: fn, ...(rest || {}) })
return useQuery(arg)
} Prevention
- Run the `remove-overloads` codemod immediately after upgrading to v5.
- Enable strict TypeScript checks so positional misuse is flagged at compile time.
- Add an ESLint rule banning multi-arg `useQuery(` calls.
- Audit wrapper hooks to forward a single options object.
When it happens
Trigger: Calling `useQuery(['todos'], fetchTodos)` (v4 positional form) under v5; passing a query-key array as the first argument; passing `null`/`undefined`/a primitive; partial migration that left some call sites in the old signature.
Common situations: Upgrading `@tanstack/react-query`/`@tanstack/preact-query` from v4 to v5 without running the `remove-overloads` codemod; copy-pasting v4 example code into a v5 project; a wrapper hook that forwards `...args` positionally.
Related errors
- Bad argument type. Starting with v5, only the "Object" form
- argument is not function.
- Expected enabled to be a boolean or a callback that returns
- Provided storage does not implement `entries` method. Garbag
- Provided storage does not implement `entries` method. Restor
AI-assisted analysis of TanStack/query@159982c80b (2026-08-12).
Data as JSON: /api/errors/cae33d9044f48440.
Report an issue: GitHub.