Created
August 30, 2022 18:26
-
-
Save jaredh159/e212b07c18761aa4d2f42d580d803442 to your computer and use it in GitHub Desktop.
CreateAsyncThunk typed fn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
AnyAction, | |
ThunkAction as LibThunkAction, | |
createAsyncThunk as libCreateAsycThunk, | |
AsyncThunkPayloadCreator, | |
AsyncThunkOptions, | |
createAction, | |
nanoid, | |
ThunkDispatch, | |
Action, | |
ActionCreatorWithPreparedPayload, | |
} from '@reduxjs/toolkit'; | |
import Result from '../api/Result'; | |
import type { State, Dispatch } from './store'; | |
export function createAsyncThunk< | |
Returned, | |
ThunkArg = void, | |
ThunkApiConfig extends AsyncThunkConfig = { state: State }, | |
>( | |
typePrefix: string, | |
payloadCreator: AsyncThunkPayloadCreator<Returned, ThunkArg, ThunkApiConfig>, | |
options?: AsyncThunkOptions<ThunkArg, ThunkApiConfig>, | |
): ReturnType<typeof libCreateAsycThunk<Returned, ThunkArg, ThunkApiConfig>> { | |
return libCreateAsycThunk<Returned, ThunkArg, ThunkApiConfig>( | |
typePrefix, | |
payloadCreator, | |
options, | |
); | |
} | |
// copied from @reduxjs/toolkit, not exported for some reason... | |
type AsyncThunkConfig = { | |
state?: unknown; | |
dispatch?: Dispatch; | |
extra?: unknown; | |
rejectValue?: unknown; | |
serializedErrorType?: unknown; | |
pendingMeta?: unknown; | |
fulfilledMeta?: unknown; | |
rejectedMeta?: unknown; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment