enchanceEndpoints -> transformResponse TS error #2726
Answered
by
phryneas
bogdan0083
asked this question in
Q&A
-
Hello guys! I'm trying to enhance the generated api and add import type {EntityState} from '@reduxjs/toolkit';
import {createEntityAdapter} from '@reduxjs/toolkit';
import type {
GetTodosApiResponse,
Todo as GeneratedTodo,
TodosGetApiResponse,
} from '@shared/api/generatedApi';
import {generatedApi} from '@shared/api/generatedApi';
const todosAdapter = createEntityAdapter<Todo>();
const initialState = todosAdapter.getInitialState();
export type Todo = GeneratedTodo;
export const todosApiSlice = generatedApi.enhanceEndpoints<string>({
addTagTypes: ['Todos'],
endpoints: {
getTodos: {
// This property shows TypeScript error:
// TS2322: Type '(response: Todo[]) => EntityState ' is not assignable to type 'undefined'.
transformResponse(response: Todo[]): EntityState<Todo> {
return todosAdapter.setAll(initialState, response);
},
},
}); The code works. The response get transformed but for some reason the ts compiler is not happy. Is there a way to fix ts error? Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
phryneas
Sep 24, 2022
Replies: 1 comment 2 replies
-
export const todosApiSlice = generatedApi.enhanceEndpoints<string>({ you should definitely not be putting that Apart from that, unfortunately currently |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
bogdan0083
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you should definitely not be putting that
<string>
there.Apart from that, unfortunately currently
enhanceEndpoints
cannot change the type of the returned value. It will work in runtime code, but they types will not accept it.I'll see if I can change that somehow soon.