diff --git a/src/effects.ts b/src/effects.ts index 7481d7a..0f3d8f1 100644 --- a/src/effects.ts +++ b/src/effects.ts @@ -24,7 +24,7 @@ function* promiseActionWrapper< ) { try { const payload: Y = yield call(worker, action); - resolvePromiseAction(action, payload as any); + resolvePromiseAction(action, payload); yield put(promiseAction.success(payload)); } catch (err) { yield rejectPromiseAction(action, err); diff --git a/src/index.ts b/src/index.ts index 995b3f5..657c600 100644 --- a/src/index.ts +++ b/src/index.ts @@ -149,6 +149,14 @@ export const promiseMiddleware: PromiseMiddleware = () => next => action => { }); }; +/** + * Resolve promise action. + * @param {PromiseAction} action Action to resolve + */ +export function resolvePromiseAction( + action: PromiseAction +): void; + /** * Resolve promise action. * @param {PromiseAction} action Action to resolve @@ -156,11 +164,25 @@ export const promiseMiddleware: PromiseMiddleware = () => next => action => { */ export function resolvePromiseAction( action: PromiseAction, - ...payload: Y extends undefined ? [] : [Y] + payload: Y +): void; + +export function resolvePromiseAction( + action: PromiseAction, + payload?: Y ) { - action.meta.promise.resolve(payload[0]); + action.meta.promise.resolve(payload); } +/** + * Reject promise action. + * @param {A} action Action to reject + */ +export function rejectPromiseAction( + action: PromiseAction +): void; + + /** * Reject promise action. * @param {A} action Action to reject @@ -168,9 +190,14 @@ export function resolvePromiseAction( */ export function rejectPromiseAction( action: PromiseAction, - ...payload: Z extends undefined ? [] : [Z] + payload: Z +): void; + +export function rejectPromiseAction( + action: PromiseAction, + payload?: Z ) { - action.meta.promise.reject(payload[0]); + action.meta.promise.reject(payload); } /**