Skip to content

Commit 5f3c105

Browse files
loursbourgphryneas
authored andcommitted
add maybe promise reject with value type test
1 parent 1f1164b commit 5f3c105

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,34 @@ const anyAction = { type: 'foo' } as AnyAction
147147
})
148148
})()
149149

150+
/**
151+
* Should handle reject withvalue within a try catch block
152+
*
153+
* Note:
154+
* this is a sample code taken from #1605
155+
*
156+
*/
157+
;(async () => {
158+
type ResultType = {
159+
text: string
160+
}
161+
const demoPromise = async (): Promise<ResultType> =>
162+
new Promise((resolve, _) => resolve({ text: '' }))
163+
const thunk = createAsyncThunk('thunk', async (args, thunkAPI) => {
164+
try {
165+
const result = await demoPromise()
166+
return result
167+
} catch (error) {
168+
return thunkAPI.rejectWithValue(error)
169+
}
170+
})
171+
createReducer({}, (builder) =>
172+
builder.addCase(thunk.fulfilled, (s, action) => {
173+
expectType<ResultType>(action.payload)
174+
})
175+
)
176+
})()
177+
150178
{
151179
interface Item {
152180
name: string

0 commit comments

Comments
 (0)