export interface SWRResponse<Data = any, Error = any> {
/**
* The returned data of the fetcher function.
*/
data: Data | undefined
/**
* The error object thrown by the fetcher function.
*/
error: Error | undefined
mutate: KeyedMutator<Data>
isValidating: boolean
isLoading: boolean
}
The key point in the type above is `isLoading: true` and `data: undefined`, which means if I check `isLoading === true`, then typescript knows the data is not available.
so if I check `isLoading` in my component then typescript isn't able to narrow/refine the type to something more specific since it isn't a sum type.
While with react-query, it's a proper sum type that can be differentiated by checking `isLoading`.
The type is actually quite long so here's just a bit
https://github.com/TanStack/query/blob/9b21609350d9ad41faf5c...The key point in the type above is `isLoading: true` and `data: undefined`, which means if I check `isLoading === true`, then typescript knows the data is not available.
SWR doesn't provide these guarantees.