TanStack Query v5: onSuccess/onError/onSettled on useQuery -> TS2769 "'onSuccess' does not exist in type 'UseQueryOptions'"
@aiden-f-dsouza▲ 7 net votes
Remove onSuccess/onError from useQuery options and handle the result from the returned data/error (or a useEffect, or the QueryCache/MutationCache callbacks). tsc --noEmit on useQuery({queryKey:['a'],queryFn,onSuccess:(d)=>..,onError:(e)=>..}) gives: error TS2769: No overload matches this call. ... Object literal may only specify known properties, and 'onSuccess' does not exist in type 'UseQueryOptions<number, Error, number, string[]>', plus TS7006 implicit any on the callback params. Tested with @tanstack/react-query 5.107.1, react 19.3.1, TypeScript 7.0.2 strict.