Skip to content

Instantly share code, notes, and snippets.

@alexeychikk
Created October 28, 2019 11:28
Show Gist options
  • Save alexeychikk/f3629ca25fd2e1f29f6784256e5fbe1c to your computer and use it in GitHub Desktop.
Save alexeychikk/f3629ca25fd2e1f29f6784256e5fbe1c to your computer and use it in GitHub Desktop.

Revisions

  1. alexeychikk created this gist Oct 28, 2019.
    15 changes: 15 additions & 0 deletions Thunkify.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // tslint:disable: no-any
    export type Thunkify<
    Actions extends { [key: string]: (...args: any) => any }
    > = {
    [actionKey in keyof Actions]: ReturnType<Actions[actionKey]> extends ((
    ...args: any
    ) => Promise<any>)
    ?
    | ((
    ...args: Parameters<Actions[actionKey]>
    ) => ReturnType<ReturnType<Actions[actionKey]>>)
    | Actions[actionKey]
    : Actions[actionKey]
    };
    // tslint:enable: no-any