I would like to implement some automatic behaviors in RTK Query. Therefore I implemented some debounced mutations and would like to also handle optimistic updates before the mutation even fired the request. The implementation works as desired.
Though I would like to also get the Typescript suggestions right. Therefore I need to extend the generic type interface MutationExtraOptions provided by RTK Query.
However, unfortunately this does not work as desired:
declare module '@reduxjs/toolkit/query/react' {
export interface MutationExtraOptions<
TagTypes extends string,
ResultType,
QueryArg,
BaseQuery extends BaseQueryFn,
ReducerPath extends string = string
> {
optimisticUpdates?: { (args: QueryArg): any[]; }[];
}
}
Where my implementation would look like this:
As you can see, the optimisticUpdates
is not recognized by VS-code.
You're probably not enhancing the right path - I'd assume that you need to
declare module '@reduxjs/toolkit/dist/query/endpointDefinitions' {
// ..
}
like RTK-Q does internally.