Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typescript types declaration #3

Open
govorov opened this issue May 9, 2018 · 1 comment
Open

Add typescript types declaration #3

govorov opened this issue May 9, 2018 · 1 comment

Comments

@govorov
Copy link

govorov commented May 9, 2018

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.

@thchia
Copy link

thchia commented May 11, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants