Skip to content

Commit cad5bf8

Browse files
committed
Initial fix for createAsyncThunk thunk types
1 parent fedd56c commit cad5bf8

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/combinedTest.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { createAsyncThunk } from './createAsyncThunk'
1+
import { Dispatch } from 'redux'
2+
import { createAsyncThunk, BaseThunkAPI } from './createAsyncThunk'
23
import { createAction, PayloadAction } from './createAction'
34
import { createSlice } from './createSlice'
45
import { configureStore } from './configureStore'
@@ -34,9 +35,18 @@ describe('Combined entity slice', () => {
3435
{ id: 'a', title: 'First' }
3536
]
3637

37-
const fetchBooksTAC = createAsyncThunk('books/fetch', async () => {
38-
return fakeBooks
39-
})
38+
const fetchBooksTAC = createAsyncThunk<
39+
string,
40+
BookModel[],
41+
void,
42+
BaseThunkAPI<{ books: BooksState }, any, Dispatch>
43+
>(
44+
'books/fetch',
45+
async (arg, { getState, dispatch, extra, requestId, signal }) => {
46+
const state = getState()
47+
return fakeBooks
48+
}
49+
)
4050

4151
const booksSlice = createSlice({
4252
name: 'books',

src/createAsyncThunk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { Dispatch } from 'redux'
22
import nanoid from 'nanoid'
33
import { createAction } from './createAction'
44

5-
type BaseThunkAPI<S, E, D extends Dispatch = Dispatch> = {
5+
export type BaseThunkAPI<S, E, D extends Dispatch = Dispatch> = {
66
dispatch: D
7-
getState: S
7+
getState: () => S
88
extra: E
99
requestId: string
1010
signal: AbortSignal

0 commit comments

Comments
 (0)