Skip to content

Commit

Permalink
Merge pull request #2885 from reduxjs/pr/fix-cat-withTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Nov 9, 2022
2 parents f7a8282 + 9b1acb3 commit 69ee99a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/toolkit/src/createAsyncThunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ If you want to use the AbortController to react to \`abort\` events, please cons
}
)
}
createAsyncThunk.withTypes = createAsyncThunk as unknown
createAsyncThunk.withTypes = () => createAsyncThunk

return createAsyncThunk as CreateAsyncThunk<AsyncThunkConfig>
})()
Expand Down
14 changes: 14 additions & 0 deletions packages/toolkit/src/tests/createAsyncThunk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,4 +953,18 @@ describe('meta', () => {
ret.meta.extraProp
}
})

test('typed createAsyncThunk.withTypes', () => {
const typedCAT = createAsyncThunk.withTypes<{
state: { s: string }
rejectValue: string
extra: { s: string; n: number }
}>()
const thunk = typedCAT('a', () => 'b')
const expectFunction = expect.any(Function)
expect(thunk.fulfilled).toEqual(expectFunction)
expect(thunk.pending).toEqual(expectFunction)
expect(thunk.rejected).toEqual(expectFunction)
expect(thunk.fulfilled.type).toBe('a/fulfilled')
})
})

0 comments on commit 69ee99a

Please sign in to comment.