rtk query компилятор typescripta ругается на getCurrentUserFavoritesMovies endpoint на queryFn
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import { token } from "../env";
import { ResponseMoviesType } from "../types/responseAllMovies";
import { ResponseMovieType } from "../types/responseMovie";
export const moviesApi = createApi({
reducerPath: "moviesApi",
baseQuery: fetchBaseQuery({
baseUrl: "https://api.kinopoisk.dev/v1.4/movie/",
prepareHeaders: (headers) => {
if (token) {
headers.set("X-API-KEY", `${token}`);
}
return headers;
},
}),
endpoints: (builder) => ({
getMovies: builder.query<ResponseMoviesType, string>({
query: (titleFilm: string) => {
return `/search?page=1&limit=10&query=${titleFilm}`;
},
}),
getMoviesById: builder.query<ResponseMovieType, string>({
query: (id) => `${id}`,
}),
getCurrentUserFavoritesMovies: builder.query<any, string[]>({
queryFn: async (
moviesId,
_queryApi,
_extraOptions,
baseQuery
) => {
if (!moviesId) return;
const results = await Promise.all(
moviesId.map((id: string) =>
baseQuery(`https://api.kinopoisk.dev/v1.4/movie/${id}`)
)
);
const merged = results.map((result) => result.data);
const errors = results
.filter((result) => result.error != null)
.map((result) => result.error);
if (errors.length > 0) return { error: errors };
return { data: merged as ResponseMoviesType[] };
},
}),
}),
});
export const {
useLazyGetMoviesQuery,
useGetMoviesByIdQuery,
useGetCurrentUserFavoritesMoviesQuery,
} = moviesApi;
сама ошибка:
Type '(moviesId: string[], _queryApi: BaseQueryApi, _extraOptions: {}, baseQuery: (arg: string | FetchArgs) => MaybePromise<QueryReturnValue<unknown, FetchBaseQueryError, FetchBaseQueryMeta>>) => Promise<...>' is not assignable to type '(arg: string[], api: BaseQueryApi, extraOptions: {}, baseQuery: (arg: string | FetchArgs) => MaybePromise<QueryReturnValue<unknown, FetchBaseQueryError, FetchBaseQueryMeta>>) => MaybePromise<'...'>'.
Type 'Promise<{ error: (FetchBaseQueryError | undefined)[]; data?: undefined; } | { data: ResponseMoviesType[]; error?: undefined; } | undefined>' is not assignable to type 'MaybePromise<QueryReturnValue<any, FetchBaseQueryError, FetchBaseQueryMeta | undefined>>'.
Type 'Promise<{ error: (FetchBaseQueryError | undefined)[]; data?: undefined; } | { data: ResponseMoviesType[]; error?: undefined; } | undefined>' is not assignable to type 'PromiseLike<QueryReturnValue<any, FetchBaseQueryError, FetchBaseQueryMeta | undefined>>'.
Types of property 'then' are incompatible.
Type '<TResult1 = { error: (FetchBaseQueryError | undefined)[]; data?: undefined; } | { data: ResponseMoviesType[]; error?: undefined; } | undefined, TResult2 = never>(onfulfilled?: ((value: { '...'; } | '...' 1 more '...' | undefined) => TResult1 | PromiseLike<'...'>) | null | undefined, onrejected?: ((reason: any) => TResult2 |...' is not assignable to type '<TResult1 = QueryReturnValue<any, FetchBaseQueryError, FetchBaseQueryMeta | undefined>, TResult2 = never>(onfulfilled?: ((value: QueryReturnValue<any, FetchBaseQueryError, FetchBaseQueryMeta | undefined>) => TResult1 | PromiseLike<'...'>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<'...'>) '...''.
Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
Types of parameters 'value' and 'value' are incompatible.
Type '{ error: (FetchBaseQueryError | undefined)[]; data?: undefined; } | { data: ResponseMoviesType[]; error?: undefined; } | undefined' is not assignable to type 'QueryReturnValue<any, FetchBaseQueryError, FetchBaseQueryMeta | undefined>'.
Type 'undefined' is not assignable to type 'QueryReturnValue<any, FetchBaseQueryError, FetchBaseQueryMeta | undefined>'.ts(2322)
endpointDefinitions.d.ts(49, 5): The expected type comes from property 'queryFn' which is declared here on type 'OmitFromUnion<QueryDefinition<string[], BaseQueryFn<string | FetchArgs, unknown, FetchBaseQueryError, {}, FetchBaseQueryMeta>, never, any, "moviesApi">, "type">'