redux-toolkit
redux-toolkit copied to clipboard
endpointDefinitions not exported from @reduxjs/toolkit/query
Hello I am using some types from endpointDefinitions to define transformedResponse return type in my endpoint enhancing, the problem is that after updating @reduxjs/toolkit to version 2.0.1 I am not able to import them from @reduxjs/toolkit/query, and this url is deepest I am allowed to go down the tree.
"@reduxjs/toolkit": "^2.0.1",
import {
DefinitionsFromApi,
OverrideResultType,
TagTypesFromApi
} from '@reduxjs/toolkit/query';
Can you show how (and why) you're using that type?
Can you show how (and why) you're using that type?
I am using code generation to generate endpoints from OpenAPI using @rtk-query/codegen-openapi. Once the endpoints are generated I am enhancing them adding the transformResponse but I keep on getting the error because typing is not correct and I do not get the right return type from the hook. So I am using this solution #3506 to type it.
I'm experiencing the same exact issue when trying to enhance a codegened API.
If it helps in the interim, setting moduleResolution to Node in your tsconfig.json allows you to do a deeper import like I'm doing below. Vite sets it to Bundler by default starting with Vite 5 as Rollup 4 requires it so it probably makes sense to export the type.
import { EntityState, createEntityAdapter } from '@reduxjs/toolkit';
import { DefinitionsFromApi, OverrideResultType } from '@reduxjs/toolkit/dist/query/endpointDefinitions';
import { FindAllCatsApiResponse, Cat, baseApi } from './base-api';
type Definitions = DefinitionsFromApi<typeof baseApi>;
type TagTypes = (typeof tags)[number];
type UpdatedFindAllCatsDef = OverrideResultType<
Definitions['findAllCats'],
EntityState<Cat, number>
>;
type UpdatedDefinitions = Omit<Definitions, 'findAllCats'> & {
findAllCats: UpdatedFindAllCatsDef;
};
const tags = ['cats'] as const;
export const catsAdapter = createEntityAdapter<Cat, number>({
selectId: (entity) => entity.id,
sortComparer: (a, b) => a.createdOn - b.createdOn,
});
export const animalApi = baseApi.enhanceEndpoints<TagTypes, UpdatedDefinitions>({
addTagTypes: tags,
endpoints: {
findAllCats: {
providesTags: ['cats'],
transformResponse: (response: FindAllCatsApiResponse) =>
catsAdapter.setAll(catsAdapter.getInitialState(), response),
},
},
});
As of 2.1.0, the types exported from that path (DefinitionsFromApi, OverrideResultType ) are all resolving to the type "never" and my overrides that worked pre-2.0 are no longer working.
which path are you using? you shouldn't be importing from /dist - as of v2.2.0 we should be exporting those types from the normal entry point.
Those types don't exist at the 'normal' entry point :(
try a reinstall - we only released v2.2.0 in the last couple hours :)
@mattoni the normal RTK Query entry point :) @reduxjs/toolkit/query or @reduxjs/toolkit/query/react .
Got it, just figured that out as you commented :) works fine from the new path!