redux 如何在使用注入端点时使用typescript将RTK-Query端点创建为空

57hvy0tb  于 2022-11-12  发布在  TypeScript
关注(0)|答案(1)|浏览(152)
export const apiSlice = createApi({
  reducerPath: 'api',
  baseQuery: fetchBaseQuery({ baseUrl: API_BASE_URL }),
  endpoints: ()={}, ==> it throws as error Typescript safety is not met
});

请提供任何帮助,我如何添加Typescript安全。

rta7y2nd

rta7y2nd1#

import { EndpointDefinitions } from '@reduxjs/toolkit/dist/query';

export const apiSlice = createApi({
  reducerPath: 'api',
  baseQuery: fetchBaseQuery({ baseUrl: API_BASE_URL }),
  endpoints: (): EndpointDefinitions => ({} as EndpointDefinitions), // <=== note here
});

这可以通过转换rtk查询终结点类型来修复。

相关问题