I am using redux-thunk in my react-native(typescript) redux project. And I am using thunkWithExtraArgument Helper to provide the reference of my apollo client variable and since I get three-argument for the return function that is
...
return async (dispatch, getState, client) =>
...
// and with typescript
import { NormalizedCacheObject } from 'apollo-cache-inmemory'
import ApolloClient from 'apollo-client'
import { Dispatch } from 'redux'
import { ReduxStore } from '../interfaces/redux.ts';
...
return async (dispatch: Dispatch, getState: () => ReduxStore, client: ApolloClient<NormalizedCacheObject>): Promise<void>) => {
...
}
that I have to type a lot of code already everywhere so is there any solution to this.
Currently, I am doing is this:
import { NormalizedCacheObject } from 'apollo-cache-inmemory'
import ApolloClient from 'apollo-client'
import { Dispatch } from 'redux'
import { ReduxStore } from '../interfaces/redux.ts'
// actually i outsources both GetState and Client types
type GetState = () => ReduxStore
// where ReduxStore is custom defined interface
type Client = ApolloClient<NormalizedCacheObject>
const fetchSomeData = (id: string) => {
return async (dispatch: Dispatch, getState: GetState, client: Client): Promise<void>) => {
...
}
}
What I tried and need is that
...
export type Thunk = (dispatch: Dispatch, getState: () => ReduxStore, client: ApolloClient<NormalizedCacheObject>): Promise<void>
...
// action creator
const fethcSomeData = (id: string) => {
return async (dispatch, getState, client): Thunk => {
...
}
}}