import { Action } from 'redux' export type PendingAction = Action & Promise

& { status: 'pending' } export type ResolvedAction = Action & { payload: P status: 'resolved' } export type RejectedAction = Action & { payload: Error status: 'rejected' } export type AsyncAction = PendingAction | ResolvedAction | RejectedAction export type GetAsyncAction = A extends PendingAction ? AsyncAction : A extends ResolvedAction ? AsyncAction : never export type GetAllActions = { [K in keyof T]: T[K] extends (...args: any[]) => infer R ? R : never }[keyof T] export type GetAllAsyncActions = GetAsyncAction> function isPromise(value: unknown): value is Promise { return value && typeof value === 'object' && typeof (value as Promise).then === 'function' } export function isPendingAction( value: unknown, ): value is PendingAction { return isPromise(value) && typeof (value as unknown as { type: 'string' }).type === 'string' } export function makeAction( type: T, impl: (...args: A) => Promise

, ): (...args: A) => PendingAction{ return (...args: A) => { const pendingAction= impl(...args) as PendingAction pendingAction.type = type pendingAction.status = 'pending' return pendingAction } }