Replies: 2 comments 3 replies
-
queryFn: async () => {
try {
const response = await axios.get(`https://dummyjson.com/products/1`);
return response.data;
} catch (exception) {
return exception;
}
}You could try something like this, of course you'll have to take care of the types. |
Beta Was this translation helpful? Give feedback.
-
|
If the error type parameter For example, it could be used like this: Where the anonymous function returns a result type (which includes both the export const queryFn =
<TData, TError, TQueryKey extends QueryKey = QueryKey, TPageParam = never>(
fn: (
// `TError` appended to type parameters here
context: QueryFunctionContext<TQueryKey, TPageParam, TError>,
) => Promise<QueryResult<TData, TError>>,
) =>
async (
// `TError` appended to type parameters here
context: QueryFunctionContext<TQueryKey, TPageParam, TError>,
): Promise<TData> => {The Of course, the most desirable would be if there was a native way; for example a type-safe alternative to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Since there is no way for me to specify the type of error thrown in typescript, I was wondering if it'd be possible to have my queryFn return { type: 'success', data: S } | { type: 'failure', data: F }. There could even be a isSuccess config that would be result => result.type === 'success'.
Beta Was this translation helpful? Give feedback.
All reactions