You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an application where I have split features into separate areas and I'm having trouble trying to use the endpoint select method.
I understand the code provided below is a little useless real world as there is nothing to select from (it is just a minimal reproduction showing the typing issue), what I am trying to do in my app is create memoized selectors for already fetched data.
src/App.tsx:6:45 - error TS2345: Argument of type '((state: { api: CombinedState<ReplaceTagTypes<{}, "airQualityStations"> & { getStations: QueryDefinition<void, BaseQueryFn<string | FetchArgs, unknown, FetchBaseQueryError, {}, FetchBaseQueryMeta>, "airQualityStations", AirQualityStation[], "api">; }, "airQualityStations", "api">; }) => AirQualityStation[] | undefin...' is not assignable to parameter of type '(state: { api: CombinedState<{}, never, "api">; }) => AirQualityStation[] | undefined'.
Types of parameters 'state' and 'state' are incompatible.
Type '{ api: CombinedState<{}, never, "api">; }' is not assignable to type '{ api: CombinedState<ReplaceTagTypes<{}, "airQualityStations"> & { getStations: QueryDefinition<void, BaseQueryFn<string | FetchArgs, unknown, FetchBaseQueryError, {}, FetchBaseQueryMeta>, "airQualityStations", AirQualityStation[], "api">; }, "airQualityStations", "api">; }'.
The types of 'api.provided' are incompatible between these types.
Property 'airQualityStations' is missing in type 'InvalidationState<never>' but required in type 'InvalidationState<"airQualityStations">'.
When the API is defined all within the createApi without using enhanceEndpoints or injectEndpoints the type works fine.
Please let me know if there is any other detail I can provide
The text was updated successfully, but these errors were encountered:
Yesh this is a bit unfortunate. It is all on a type level, so for now it should be working just fine, but give a type error - until we get a better idea to do this, adding a // @ts-expect-error is probably the best you can do.
Generally though, you should probably be using useQuery with selectFromResult if you ever want to access cache values from components. The selectors are just an escape hatch and it is perfectly fine to call useQuery from 20 components at once.
I have an application where I have split features into separate areas and I'm having trouble trying to use the endpoint
select
method.I understand the code provided below is a little useless real world as there is nothing to select from (it is just a minimal reproduction showing the typing issue), what I am trying to do in my app is create memoized selectors for already fetched data.
Reproduction repos:
(code split not working): https://github.com/littlejon/rtk-selector-typing-issue/tree/code_splitting_not_working
(all in the createApi): https://github.com/littlejon/rtk-selector-typing-issue/tree/working_all_in_one
store.ts
api.ts
App.tsx
Line 6 gives the following type error.
When the API is defined all within the
createApi
without usingenhanceEndpoints
orinjectEndpoints
the type works fine.Please let me know if there is any other detail I can provide
The text was updated successfully, but these errors were encountered: