Skip to content

Commit

Permalink
add maybe promise reject with value type test
Browse files Browse the repository at this point in the history
  • Loading branch information
loursbourg committed Oct 20, 2021
1 parent c211346 commit 055036d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/toolkit/src/tests/createAsyncThunk.typetest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@ const anyAction = { type: 'foo' } as AnyAction
})
})()

/**
* Should handle reject withvalue within a try catch block
*
* Note:
* this is a sample code taken from #1605
*
*/
;(async () => {
type ResultType = {
text: string
}
const demoPromise = async (): Promise<ResultType> =>
new Promise((resolve, _) => resolve({ text: '' }))
const thunk = createAsyncThunk('thunk', async (args, thunkAPI) => {
try {
const result = await demoPromise()
return result
} catch (error) {
return thunkAPI.rejectWithValue(error)
}
})
createReducer({}, (builder) =>
builder.addCase(thunk.fulfilled, (s, action) => {
expectType<ResultType>(action.payload)
})
)
})()

{
interface Item {
name: string
Expand Down

0 comments on commit 055036d

Please sign in to comment.