以下代码使用 RTK 查询创建 Redux Hook:
export const specialtiesApi = createApi({
reducerPath: 'specialtiesApi',
baseQuery: fetchBaseQuery({ baseUrl: 'https://someplace.com/' }),
endpoints: (builder) => ({
getSpecialties: builder.query({
query: (name) => `specialties`,
}),
}),
});
export const { useGetSpecialtiesQuery } = specialtiesApi;
最后一行代码抛出 Typescript 编译时错误:
Property 'useGetSpecialtiesQuery' does not exist on type 'Api<BaseQueryFn<string | FetchArgs, unknown, FetchBaseQueryError, {}, FetchBaseQueryMeta>, { getSpecialties: QueryDefinition<...>; }, "specialtiesApi", never, unique symbol>'
我的代码使用 Typescript 4.3.5改编自https://redux-toolkit.js.org/rtk-query/usage-with-typescript 。
我看不出它有什么问题。有任何想法吗?