redux-promise-listener icon indicating copy to clipboard operation
redux-promise-listener copied to clipboard

Add typescript types declaration

Open govorov opened this issue 6 years ago • 1 comments

Hi,

redux-promise-listener doesn't have typescript type definitions at the moment. I tried to convert existing flow type definitions and I ended up with this:

declare module 'redux-promise-listener' {

    import { Store } from 'redux';

    export type State = any;

    export interface Action {
        type: string;
        payload?: any;
    }

    export type Next = (action: Action) => State;

    export type SetPayload = (action: Action, payload: any) => Action;

    export type GetPayload = (action: Action) => any;

    // I'm not sure about this generic
    export type Middleware<S = any> = (store: Store<S>) => (
        (next: Next) => (
            (action: Action) => State
        )
    );

    export interface Config {
        start: string;
        resolve: string;
        reject: string;
        setPayload?: SetPayload;
        getPayload?: GetPayload;
        getError?: GetPayload;
    }


    export interface AsyncFunction {
        asyncFunction: (...args: Array<any>) => Promise<any>;
        unsubscribe: () => void;
    }


    export type PromiseListener = {
        middleware: Middleware,
        createAsyncFunction: (config: Config) => AsyncFunction
    };


    export default function createListener(): PromiseListener;

}

I'm not proposing a pull request because I'm not sure if this declaration is correct and whether you find this idea useful.

Thank you.

govorov avatar May 09 '18 01:05 govorov

I think you can depend on the redux type definition for Middleware, rather than re-typing it here.

thchia avatar May 11 '18 05:05 thchia