skip to Main Content

i got this error ts(2742) cannot be named without a reference for all rtk query actions, how i can fix it?

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'

export const postsApi = createApi({
  reducerPath: "api",
  baseQuery: fetchBaseQuery({ baseUrl: "url" }),
  endpoints: (builder) => ({
    getChaptersList: builder.query({
      query: () => "/chapters-list/",
    }),
    getChapter: builder.query({
      query: (chapter:string) => `/chapters-list/${chapter}/`,
    }),
  }),
});


export const { 
    useGetChaptersListQuery,
    useGetChapterQuery 
} = postsApi;


The inferred type of 'useGetChapterQuery' cannot be named without a reference to '../../../node_modules/@reduxjs/toolkit/dist/query/react/buildHooks'. This is likely not portable. A type annotation is necessary.ts(2742)

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    Am used vite latest version, i set a little older vite version and now i don't have this ts error :]


  2. there are two solutions.

    1st:

    assert "any" type while exporting from the Redux API file:

    export const { useLoginMutation, useSignUpMutation } = baseApi as any;

    2nd:
    You can export baseApi and call the hooks like this:

    import baseApi from ‘../redux/api/baseApi’;

    const [login] = baseApi.useLoginMutation();

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search