rtk-incubator / rtk-query

Data fetching and caching addon for Redux Toolkit
https://redux-toolkit.js.org/rtk-query/overview
MIT License
626 stars 31 forks source link

BaseQueryEnhancer is dropping types of FetchBaseQuery? #98

Closed msutkowski closed 3 years ago

msutkowski commented 3 years ago

Need to investigate, but it appears that BaseQueryEnhancer is dropping the types of what's passed into it.

image

Current workaround is to:

const isBaseQueryError = (
    result: any
  ): result is { error: FetchBaseQueryError } => 'error' in result;

  if (isBaseQueryError(result)) {
    if (result.error.status === 401) {
      api.dispatch(logoutUser());
    }
  }
msutkowski commented 3 years ago

Adding notes here for posterity before adding docs to the site. If you find that your error type is unknown when using hooks, this applies to you.

This can be solved by:

const baseQuery = retry(otherEnhancer(fetchBaseQuery({ baseUrl: 'http://example.com/' })));`
const api = createApi({ baseQuery, endpoints: () => ({}) });