@@ -7,7 +7,10 @@ import type { AxiosError } from 'axios'
7
7
import apiRequest from 'axios'
8
8
import type { IsAny , IsUnknown } from '@internal/tsHelpers'
9
9
import { expectType } from './helpers'
10
- import { AsyncThunkPayloadCreator } from '@internal/createAsyncThunk'
10
+ import type {
11
+ AsyncThunkFulfilledActionCreator ,
12
+ AsyncThunkRejectedActionCreator ,
13
+ } from '@internal/createAsyncThunk'
11
14
12
15
const defaultDispatch = ( ( ) => { } ) as ThunkDispatch < { } , any , AnyAction >
13
16
const anyAction = { type : 'foo' } as AnyAction
@@ -422,6 +425,44 @@ const anyAction = { type: 'foo' } as AnyAction
422
425
expectType < AsyncThunk < 'ret' , void , { } > > ( thunk )
423
426
}
424
427
428
+ // createAsyncThunk rejectWithValue without generics: Expect correct return type
429
+ {
430
+ const asyncThunk = createAsyncThunk (
431
+ 'test' ,
432
+ ( _ : void , { rejectWithValue } ) => {
433
+ try {
434
+ return Promise . resolve ( true )
435
+ } catch ( e ) {
436
+ return rejectWithValue ( e )
437
+ }
438
+ }
439
+ )
440
+
441
+ defaultDispatch ( asyncThunk ( ) )
442
+ . then ( ( result ) => {
443
+ if ( asyncThunk . fulfilled . match ( result ) ) {
444
+ expectType < ReturnType < AsyncThunkFulfilledActionCreator < boolean , void > > > (
445
+ result
446
+ )
447
+ expectType < boolean > ( result . payload )
448
+ // @ts -expect-error
449
+ expectType < any > ( result . error )
450
+ } else {
451
+ expectType < ReturnType < AsyncThunkRejectedActionCreator < unknown , void > > > (
452
+ result
453
+ )
454
+ expectType < SerializedError > ( result . error )
455
+ expectType < unknown > ( result . payload )
456
+ }
457
+
458
+ return result
459
+ } )
460
+ . then ( unwrapResult )
461
+ . then ( ( unwrapped ) => {
462
+ expectType < boolean > ( unwrapped )
463
+ } )
464
+ }
465
+
425
466
{
426
467
type Funky = { somethingElse : 'Funky!' }
427
468
function funkySerializeError ( err : any ) : Funky {
0 commit comments