@@ -21,6 +21,8 @@ import type { QueryResultSelectorResult } from './buildSelectors'
21
21
import type { Dispatch } from 'redux'
22
22
import { isNotNullish } from '../utils/isNotNullish'
23
23
import { countObjectKeys } from '../utils/countObjectKeys'
24
+ import type { SafePromise } from '../../tsHelpers'
25
+ import { asSafePromise } from '../../tsHelpers'
24
26
25
27
declare module './module' {
26
28
export interface ApiEndpointQuery <
@@ -60,7 +62,7 @@ type StartQueryActionCreator<
60
62
61
63
export type QueryActionCreatorResult <
62
64
D extends QueryDefinition < any , any , any , any >
63
- > = Promise < QueryResultSelectorResult < D > > & {
65
+ > = SafePromise < QueryResultSelectorResult < D > > & {
64
66
arg : QueryArgFrom < D >
65
67
requestId : string
66
68
subscriptionOptions : SubscriptionOptions | undefined
@@ -90,7 +92,7 @@ type StartMutationActionCreator<
90
92
91
93
export type MutationActionCreatorResult <
92
94
D extends MutationDefinition < any , any , any , any >
93
- > = Promise <
95
+ > = SafePromise <
94
96
| { data : ResultTypeFrom < D > }
95
97
| {
96
98
error :
@@ -335,7 +337,7 @@ You must add the middleware for RTK-Query to function correctly!`
335
337
const selectFromState = ( ) => selector ( getState ( ) )
336
338
337
339
const statePromise : QueryActionCreatorResult < any > = Object . assign (
338
- forceQueryFn
340
+ ( forceQueryFn
339
341
? // a query has been forced (upsertQueryData)
340
342
// -> we want to resolve it once data has been written with the data that will be written
341
343
thunkResult . then ( selectFromState )
@@ -345,7 +347,9 @@ You must add the middleware for RTK-Query to function correctly!`
345
347
Promise . resolve ( stateAfter )
346
348
: // query just started or one is already in flight
347
349
// -> wait for the running query, then resolve with data from after that
348
- Promise . all ( [ runningQuery , thunkResult ] ) . then ( selectFromState ) ,
350
+ Promise . all ( [ runningQuery , thunkResult ] ) . then (
351
+ selectFromState
352
+ ) ) as SafePromise < any > ,
349
353
{
350
354
arg,
351
355
requestId,
@@ -421,10 +425,10 @@ You must add the middleware for RTK-Query to function correctly!`
421
425
const thunkResult = dispatch ( thunk )
422
426
middlewareWarning ( dispatch )
423
427
const { requestId, abort, unwrap } = thunkResult
424
- const returnValuePromise = thunkResult
425
- . unwrap ( )
426
- . then ( ( data ) => ( { data } ) )
427
- . catch ( ( error ) => ( { error } ) )
428
+ const returnValuePromise = asSafePromise (
429
+ thunkResult . unwrap ( ) . then ( ( data ) => ( { data } ) ) ,
430
+ ( error ) => ( { error } )
431
+ )
428
432
429
433
const reset = ( ) => {
430
434
dispatch ( removeMutationResult ( { requestId, fixedCacheKey } ) )
0 commit comments