Reputation: 143
I use rtk query and I have type error with this content :
Property 'data' does not exist on type 'FetchBaseQueryError | SerializedError'.
Property 'data' does not exist on type 'SerializedError'
and this the code I wrote :
const { data, isError, isSuccess, isLoading, error } = useGetClerkListQuery({
page,
count: value,
order_by: orderBy,
search: searchTerm,
})
if (isError && error) {
toast.error(error.data.status.message)
}
also this is my rtk mutation:
getClerkList: builder.query<{ result: IClerkList }, IClerkParamsType>({
query: params => {
return {
url: '/clerk/list/',
params,
}
},
providesTags: ['clerk'],
}),
Upvotes: 2
Views: 2231
Reputation: 44226
You need to narrow the error type down to FetchBaseQueryError first:
if (isError && error && 'status' in error) {
But generally note, that the data returned from the server will be unknown
and you have to verify that it has the right structure and then manually cast it.
It's an error after all, so also something unexpected could have wrong and it could have an unexpected structure as a result.
Upvotes: 1