Currently, I am utilizing react-query
's useQueries
function to create a unique custom hook named useArtists
:
type SuccessResponse = {
artist: {
name: string
}
};
const fetchArtist = async (artistId: string): Promise<SuccessResponse> => {
const response = await axios.get(`/artists/${artistId}`);
if (response.status !== 200) {
throw response.data.error ?? "Unknown error";
}
return response.data;
};
export const useArtists = (artistIds: string[]) => {
return useQueries({
queries: artistIds.map((artistId) => {
return {
queryKey: ["artists", artistId],
queryFn: () => fetchArtist(artistId),
};
}),
});
};
The current inferred return type of useArtists
is
UseQueryResult<SuccessResponse, unknown>[]
.
In order to include the return type of the error, which is string
, how can I update the return type to be
UseQueryResult<SuccessResponse, string>[]
?