Skip to content

Typescript: Matching rtk-query actions with status code #3432

Answered by EskiMojo14
mauriceoc asked this question in Q&A
Discussion options

You must be logged in to vote

is there? yes
will you want to do it? nope

    return isRejected(action) 
    && action.payload === 'Unauthorized' 
    && 'baseQueryMeta' in action.meta
    && typeof action.meta.baseQueryMeta === "object"
    && !!action.meta.baseQueryMeta
    && 'response' in action.meta.baseQueryMeta
    && action.meta.baseQueryMeta.response instanceof Response
    && action.meta.baseQueryMeta.response.status === 401;

i would rather skip a few steps, and use a type guard:

const hasRTKQMeta = (action: any): action is {
    meta: {
        baseQueryMeta: {
            request: Request
            response?: Response
        }
    }
} => action?.meta?.baseQueryMeta?.request instanceof Request

const is40…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mauriceoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants