QueryClientConfig is missing type args
Describe the bug
The type QueryClientConfig is missing type args. It is currently defined as
export interface QueryClientConfig {
queryCache?: QueryCache;
mutationCache?: MutationCache;
defaultOptions?: DefaultOptions;
}
and used in the QueryClient constructor as
constructor(config: QueryClientConfig = {}) // ...
This makes it impossible to define a typed config object with types other than unknown.
Your minimal, reproducible example
Already in bug description
Steps to reproduce
In bug description
Expected behavior
Ability to create a typed config with types other than unknown used it's porpertyes type args.
const defaultOptions: DefaultOptions<ApiError> = {/* ... */};
const queryClient = new QueryClient({ defaultOptions });
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
N/A
react-query version
"react-query": "3.34.16",
TypeScript version
"typescript": "4.6.2",
Additional context
No response
Related to this is the fact that when creating a defaultOptions object, there's a type error for the mutationFn prop,
const defaultOptions: DefaultOptions = {};
const queries: QueryObserverOptions = {};
const mutations: MutationObserverOptions = {};
queries.onError = (error) => {/*...*/};
mutations.onError = (error) => {/*...*/};
defaultOptions.queries = queries;
defaultOptions.mutations = mutations;
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Types of property 'mutationFn' are incompatible.
Type 'MutationFunction<unknown, void> | undefined' is not assignable to type 'MutationFunction<unknown, unknown> | undefined'.
Type 'MutationFunction<unknown, void>' is not assignable to type 'MutationFunction<unknown, unknown>'.
Type 'unknown' is not assignable to type 'void'.
42 defaultOptions.mutations = mutations;
~~~~~~~~~~~~~~~~~~~~~~~~
*/
const queryClient = new QueryClient({ defaultOptions });
Are they worried that we could potentially use a different error type on some queries? My use case is openapi gen client so we internally guarantee an error type of ApiError. I feel like we should be given the option to define this if we need
can someone please provide a reproduction in https://typescriptlang.org/play ? From the description alone, I don't understand the problem fully.
@aryzing Looks like you wish QueryClientConfig/DefaultOptions types to be generic and to take type args because error type is predictable? If I'm understanding you correctly, this discussion has talked about it already.
The discussion proved useful, will close.