reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.48k stars 1.13k forks source link

Failure to recognize type definition of mutation argument #4396

Closed treyorr closed 1 month ago

treyorr commented 1 month ago

Hello. I am trying to implement a RTK mutation in which I pass in two arguments in a Typescript project.

export const exampleApi= createApi({
    reducerPath: "myPath",
    baseQuery: fetchBaseQuery({ baseUrl: url }),
    endpoints: (builder) => ({
        sendVerificationText: builder.mutation({
            query: (phone: string) => ({
                url: "user/sendVerificationText",
                method: "POST",
                body: { phone },
            }),
        }),
        verifyVerificationCode: builder.mutation<any, VerificationCodeRequestBody>({
            query: (body) => {
                return {
                    url: "user/verifyVerificationCode",
                    method: "POST",
                    body: body,
                };
            },
        }),
    }),
});

I am attempting to pass in two variables using the method in the hook generated by RTK.

verifyVerificationCode({ phone, otp });

However, I keep recieving the error: Argument of type '{ phone: string; otp: string; }' is not assignable to parameter of type 'string'.

I have read previous inquiries into this behavior, but yet the solution still is evading me. Thank you.

treyorr commented 1 month ago

Sorry , I had a really dumb mistake that evaded me for a few hours. This can be closed since I was using the wrong hook