@@ -18,6 +18,7 @@ import {
1818 type UseMutationOptions ,
1919 type UseQueryOptions ,
2020} from '@tanstack/react-query'
21+ import { type SetNonNullable } from 'type-fest'
2122
2223import { invariant } from '@oxide/util'
2324
@@ -138,7 +139,7 @@ export const getUsePrefetchedApiQuery =
138139 options : UseQueryOtherOptions < Result < A [ M ] > , ApiError > = { }
139140 ) => {
140141 const queryKey = [ method , params ]
141- const { data , ... rest } = useQuery ( {
142+ const result = useQuery ( {
142143 queryKey,
143144 // no catch, let unexpected errors bubble up
144145 queryFn : ( { signal } ) => api [ method ] ( params , { signal } ) . then ( handleResult ( method ) ) ,
@@ -149,8 +150,13 @@ export const getUsePrefetchedApiQuery =
149150 throwOnError : ( err ) => err . statusCode === 404 ,
150151 ...options ,
151152 } )
152- invariant ( data , `Expected query to be prefetched. Key: ${ JSON . stringify ( queryKey ) } ` )
153- return { data, ...rest }
153+ invariant (
154+ result . data ,
155+ `Expected query to be prefetched. Key: ${ JSON . stringify ( queryKey ) } `
156+ )
157+ // TS infers non-nullable on a freestanding variable, but doesn't like to do
158+ // it on a property. So we give it a hint
159+ return result as SetNonNullable < typeof result , 'data' >
154160 }
155161
156162const ERRORS_ALLOWED = 'errors-allowed'
0 commit comments