Skip to content

Commit 69ee99a

Browse files
authored
Merge pull request #2885 from reduxjs/pr/fix-cat-withTypes
2 parents f7a8282 + 9b1acb3 commit 69ee99a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/toolkit/src/createAsyncThunk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ If you want to use the AbortController to react to \`abort\` events, please cons
708708
}
709709
)
710710
}
711-
createAsyncThunk.withTypes = createAsyncThunk as unknown
711+
createAsyncThunk.withTypes = () => createAsyncThunk
712712

713713
return createAsyncThunk as CreateAsyncThunk<AsyncThunkConfig>
714714
})()

packages/toolkit/src/tests/createAsyncThunk.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,4 +953,18 @@ describe('meta', () => {
953953
ret.meta.extraProp
954954
}
955955
})
956+
957+
test('typed createAsyncThunk.withTypes', () => {
958+
const typedCAT = createAsyncThunk.withTypes<{
959+
state: { s: string }
960+
rejectValue: string
961+
extra: { s: string; n: number }
962+
}>()
963+
const thunk = typedCAT('a', () => 'b')
964+
const expectFunction = expect.any(Function)
965+
expect(thunk.fulfilled).toEqual(expectFunction)
966+
expect(thunk.pending).toEqual(expectFunction)
967+
expect(thunk.rejected).toEqual(expectFunction)
968+
expect(thunk.fulfilled.type).toBe('a/fulfilled')
969+
})
956970
})

0 commit comments

Comments
 (0)