export interface AnyAction { type: any; } export declare type Meta = null | { [key: string]: any; }; export interface Action extends AnyAction { type: string; payload: Payload; error?: boolean; meta?: Meta; } /** * Returns `true` if action has the same type as action creator. * Defines Type Guard that lets TypeScript know `payload` type inside blocks * where `isType` returned `true`. * * @example * * const somethingHappened = * actionCreator<{foo: string}>('SOMETHING_HAPPENED'); * * if (isType(action, somethingHappened)) { * // action.payload has type {foo: string} * } */ export declare function isType(action: AnyAction, actionCreator: ActionCreator): action is Action; export interface ActionCreator { type: string; /** * Identical to `isType` except it is exposed as a bound method of an action * creator. Since it is bound and takes a single argument it is ideal for * passing to a filtering function like `Array.prototype.filter` or * RxJS's `Observable.prototype.filter`. * * @example * * const somethingHappened = * actionCreator<{foo: string}>('SOMETHING_HAPPENED'); * const somethingElseHappened = * actionCreator<{bar: number}>('SOMETHING_ELSE_HAPPENED'); * * if (somethingHappened.match(action)) { * // action.payload has type {foo: string} * } * * const actionArray = [ * somethingHappened({foo: 'foo'}), * somethingElseHappened({bar: 5}), * ]; * * // somethingHappenedArray has inferred type Action<{foo: string}>[] * const somethingHappenedArray = * actionArray.filter(somethingHappened.match); */ match: (action: AnyAction) => action is Action; /** * Creates action with given payload and metadata. * * @param payload Action payload. * @param meta Action metadata. Merged with `commonMeta` of Action Creator. */ (payload: Payload, meta?: Meta): Action; } export declare type Success = ({ params: Params; } | (Params extends void ? { params?: Params; } : never)) & ({ result: Result; } | (Result extends void ? { result?: Result; } : never)); export declare type Failure = ({ params: Params; } | (Params extends void ? { params?: Params; } : never)) & { error: Error; }; export interface AsyncActionCreators { type: string; started: ActionCreator; done: ActionCreator>; failed: ActionCreator>; } export interface ActionCreatorFactory { /** * Creates Action Creator that produces actions with given `type` and payload * of type `Payload`. * * @param type Type of created actions. * @param commonMeta Metadata added to created actions. * @param isError Defines whether created actions are error actions. */ (type: string, commonMeta?: Meta, isError?: boolean): ActionCreator; /** * Creates Action Creator that produces actions with given `type` and payload * of type `Payload`. * * @param type Type of created actions. * @param commonMeta Metadata added to created actions. * @param isError Function that detects whether action is error given the * payload. */ (type: string, commonMeta?: Meta, isError?: (payload: Payload) => boolean): ActionCreator; /** * Creates three Action Creators: * * `started: ActionCreator` * * `done: ActionCreator<{params: Params, result: Result}>` * * `failed: ActionCreator<{params: Params, error: Error}>` * * Useful to wrap asynchronous processes. * * @param type Prefix for types of created actions, which will have types * `${type}_STARTED`, `${type}_DONE` and `${type}_FAILED`. * @param commonMeta Metadata added to created actions. */ async(type: string, commonMeta?: Meta): AsyncActionCreators; } /** * Creates Action Creator factory with optional prefix for action types. * @param prefix Prefix to be prepended to action types as `/`. * @param defaultIsError Function that detects whether action is error given the * payload. Default is `payload => payload instanceof Error`. */ export declare function actionCreatorFactory(prefix?: string | null, defaultIsError?: (payload: any) => boolean): ActionCreatorFactory; export default actionCreatorFactory;