Browse Source

fix(queryclient): Fix typing for useApiQuery options (#48887)

The options passed to useApiQuery were expecting `TApiResponse`, but
actually we now have `ApiResult<TApiResponse>`.
Malachi Willey 1 year ago
parent
commit
30922530f8

+ 2 - 2
static/app/components/events/interfaces/crashContent/exception/useSourceMapDebug.tsx

@@ -125,7 +125,7 @@ export function useSourceMapDebugQueries(props: UseSourceMapDebugProps[]) {
     retry: false,
   };
   return useQueries({
-    queries: props.map<UseApiQueryOptions<SourceMapDebugResponse>>(p => {
+    queries: props.map(p => {
       const key = sourceMapDebugQuery(p);
       return {
         queryKey: sourceMapDebugQuery(p),
@@ -134,7 +134,7 @@ export function useSourceMapDebugQueries(props: UseSourceMapDebugProps[]) {
           api.requestPromise(key[0], {
             method: 'GET',
             query: key[1]?.query,
-          }),
+          }) as Promise<SourceMapDebugResponse>,
         ...options,
       };
     }),

+ 2 - 2
static/app/components/onboarding/footer.tsx

@@ -67,7 +67,7 @@ export function Footer({projectSlug, projectId, router, newOrg}: Props) {
       !!projectSlug &&
       !firstError &&
       projectData?.status === OnboardingProjectStatus.WAITING, // Fetch only if the project is available and we have not yet received an error,
-    onSuccess: data => {
+    onSuccess: ([data]) => {
       setFirstError(data.firstEvent);
     },
   });
@@ -82,7 +82,7 @@ export function Footer({projectSlug, projectId, router, newOrg}: Props) {
       !!firstError &&
       !firstIssue &&
       projectData?.status === OnboardingProjectStatus.PROCESSING, // Only fetch if an error event is received and we have not yet located the first issue,
-    onSuccess: data => {
+    onSuccess: ([data]) => {
       setFirstIssue(data.find((issue: Group) => issue.firstSeen === firstError));
     },
   });

+ 2 - 2
static/app/components/onboarding/footerWithViewSampleErrorButton.tsx

@@ -73,7 +73,7 @@ export function FooterWithViewSampleErrorButton({
       !!projectSlug &&
       !firstError &&
       projectData?.status === OnboardingProjectStatus.WAITING, // Fetch only if the project is available and we have not yet received an error,
-    onSuccess: data => {
+    onSuccess: ([data]) => {
       setFirstError(data.firstEvent);
     },
   });
@@ -88,7 +88,7 @@ export function FooterWithViewSampleErrorButton({
       !!firstError &&
       !firstIssue &&
       projectData?.status === OnboardingProjectStatus.PROCESSING, // Only fetch if an error event is received and we have not yet located the first issue,
-    onSuccess: data => {
+    onSuccess: ([data]) => {
       setFirstIssue(data.find((issue: Group) => issue.firstSeen === firstError));
     },
   });

+ 1 - 1
static/app/components/onboarding/useRecentCreatedProject.tsx

@@ -26,7 +26,7 @@ export function useRecentCreatedProject({
         if (!data) {
           return false;
         }
-        const [projectData] = data as unknown as [Project | undefined, any, any];
+        const [projectData] = data;
         return projectData?.firstEvent ? false : DEFAULT_POLL_INTERVAL_MS;
       },
     }

+ 7 - 2
static/app/utils/queryClient.tsx

@@ -28,7 +28,7 @@ interface UseApiQueryOptions<TApiResponse, TError = RequestError>
     reactQuery.UseQueryOptions<
       ApiResult<TApiResponse>,
       TError,
-      TApiResponse,
+      ApiResult<TApiResponse>,
       ApiQueryKey
     >,
     // This is an explicit option in our function
@@ -111,11 +111,16 @@ function useApiQuery<TResponseData, TError = RequestError>(
 
   const {data, ...rest} = reactQuery.useQuery(queryKey, queryFn, options);
 
-  return {
+  const queryResult = {
     data: data?.[0],
     getResponseHeader: data?.[2]?.getResponseHeader,
     ...rest,
   };
+
+  // XXX: We need to cast here because unwrapping `data` breaks the type returned by
+  //      useQuery above. The react-query library's UseQueryResult is a union type and
+  //      too complex to recreate here so casting the entire object is more appropriate.
+  return queryResult as UseApiQueryResult<TResponseData, TError>;
 }
 
 /**