-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
The latest version of the redux toolkit package throws typescript while creating the custom selector based on rtk-query state information.
Expected: Should get compiled successfully.
it can be replicated in the redux-toolkit's typescript version scaffold.
Steps to replicate typescript scaffold):
- create file named
api.ts
inapp
folder asapp/api.ts
as below:
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import { RootState } from "./store";
// initialize an empty api service that we'll inject endpoints into later as needed
const apiBase = createApi({
refetchOnFocus: false, // Re-fetching on window focus
refetchOnReconnect: false, // Re-fetching on network reconnection
keepUnusedDataFor: 60,
refetchOnMountOrArgChange: false, // Encouraging re-fetching
baseQuery: fetchBaseQuery({
baseUrl: "http://example.com",
}),
endpoints: (builder) => ({
currencies: builder.query<{ [k: string]: number }, void>({
query: () => ({
url: "currencies",
method: "GET",
}),
}),
}),
});
export default apiBase;
const selectCurrenciesEndpoint = (state: RootState) =>
apiBase.endpoints.currencies.select()(state);
- Update
store.ts
as below:
export const store = configureStore({
reducer: {
api: apiBase.reducer,
counter: counterReducer,
},
});
You'll start seeing the error message as defined above at the line apiBase.endpoints.currencies.select()(state);
.
Looking forward to your response.
PS. in middle of upgrading my project and looking for the solution :-)
Thanks,
Manish
Metadata
Metadata
Assignees
Labels
No labels