I am trying to pass a string to a query in Redux Toolkit (TypeScript)
foo: builder.query<FooResponse, void>({
query: (bar) => ({ // bar gets automatically the type QueryArg assigned
url: SOME_URL_CONSTANT,
params: {bar}
}),
transformResponse(response: FooResponse[]): FooResponse{
return response[0]
}
}),
When I am calling
useFooQuery("whatever")
The TypeScript compiler complains
Argument of type '"whatever"' is not assignable to parameter of type 'void | unique symbol'. When I try to change
query: (bar: string) => ({...
I get
Type '(bar: string) => { url: string; params: { bar: string; }; }' is not assignable to type '(arg: void) => string | FetchArgs'. Types of parameters 'bar' and 'arg' are incompatible. Type 'void' is not assignable to type 'string'.
So, how do I pass a parameter to the query function?